FCP Assignment 4
Anurag Bhunia
Chapter 6
Q1.
#include <stdio.h>
int main(){
int n;
float x;
printf("How many numbers do you want to give?");
scanf("%d",&n);
printf("Enter the number:");
scanf("%f",&x);
for(int i=0;i<n-1;i++){
float y;
printf("Enter the number:");
scanf("%f",&y);
if(y>x){
x=y;
}
}
printf("The largest number is %f",x);
}
Q3.
#include <stdio.h>
int gcd(int a,int b){
int m,d=1;
if(a>b){
m=b;
}
else{
m=a;
}
for(int i=2;i<=m;i++){
if(a%i==0 && b%i==0){
d=i;
}
}
return d;
}
int main(){
int a,b;
printf("Enter the fraction:");
scanf("%d/%d",&a,&b);
printf("The fraction in the lowest form is
%d/%d",a/gcd(a,b),b/gcd(a,b));
}
Q5.
#include <stdio.h>
int main(){
int n,d=0;
printf("Enter the number:");
scanf("%d",&n);
while(n>0){
d=10*d+n%10;
n/=10;
}
printf("The reversed number is %d",d);
}
Q11.
#include <stdio.h>
double fact(int n){
if(n==0){
return 1;
}
else{
return n*fact(n-1);
}
}
int main(){
int n;
double s=0;
printf("Till how many terms do you want to estimate e?");
scanf("%d",&n);
for(int i=0;i<=n;i++){
s+=1.0/fact(i);
}
printf("The estimated value of e is %f",s);
}