1. //prepared for Dr. Al-Qadi
//the answer for Q1
#include<stdio.h>
#include<stdlib.h>
int main(){
FILE *in;
int no;
double status;
in=fopen("numbers.txt","r");
if(in==NULL)
exit(1);
status=fscanf(in,"%d",&no);
while(status!=EOF){
if(no%2==0)
printf("The number that exist in file 'numbers.txt' is %dnn",no);
status=fscanf(in,"%d",&no);
}
fclose(in);
system("pause");
return(0);
}
2. //prepared for Dr. Al-Qadi
//the answer for Q2
#include<stdio.h>
#include<stdlib.h>
void perfect(int no);
int main(){
int no;
printf("Enter a value>");
scanf("%d",&no);
perfect(no);
system("pause");
return(0);
}
void perfect(int no){
int i,sum=0;
for(i=1;i<no;i++){
if(no%i==0)
sum+=i;
}
if(sum==no)
printf("%d is perfectnn",no);
else
printf("%d is not perfectnn",no);
}
3. //prepared for Dr. Al-Qadi
//the answer for Q3
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void NumTest(int a,int b,int c,double *r1,double *r2);
int main(){
int a,b,c;
double r1,r2;
printf("Enter the values of a,b and c>");
scanf("%d %d %d",&a,&b,&c);
NumTest(a,b,c,&r1,&r2);
printf("r1= %.2f t r2= %.2f nn",r1,r2);
system("pause");
return(0);
}
void NumTest(int a,int b,int c,double *r1,double *r2){
*r1 = (-b + sqrt(b*b - 4*a*c))/ 2.0*a;
*r2 = (-b - sqrt(b*b - 4*a*c))/ 2.0*a;
}
4. //prepared for Dr. Al-Qadi
//the answer for Q4
#include<stdio.h>
#include<stdlib.h>
double sum(double num1,double num2);
int main(){
double num1, num2, result;
printf("Enter two numbers>");
scanf("%lf %lf",&num1,&num2);
result = sum(num1,num2);
printf("The sum of all numbers in between = %.fnn",result);
system("pause");
return(0);
}
double sum(double num1,double num2){
if(num2-num1==1)
return num1+num2;
else
return num1 + sum(num1+1,num2);
}