0% found this document useful (0 votes)
7 views3 pages

C Programming Assignments Solutions

The document contains code snippets for various programming assignments in C. It includes solutions for finding the largest number, calculating the greatest common divisor (GCD) of two integers, reversing a number, and estimating the value of e using a series expansion. Each code segment is accompanied by user prompts for input and outputs the respective results.

Uploaded by

Anurag Bhunia
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

C Programming Assignments Solutions

The document contains code snippets for various programming assignments in C. It includes solutions for finding the largest number, calculating the greatest common divisor (GCD) of two integers, reversing a number, and estimating the value of e using a series expansion. Each code segment is accompanied by user prompts for input and outputs the respective results.

Uploaded by

Anurag Bhunia
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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);
}

You might also like