the factorial of non-negative integer n is written n! and
is defined as follows:
n!=n*(n-1)*(n-2)........1(for values of n greater than or
equal to 1 and
n!=1(for n=0)
Perform the following
1.write a c program that reads a non-negative integer and
computes and prints its factorial.
2. write a C program that estimates the value of the
mathematical constant e by using the formula:
e=1+1/!+1/2!+1/3!+....
3. write a c program the computes the value ex by using the
formula
ex=1+x/1!+xsquare/2!+xcube/3!+....

Answers were Sorted based on User's Feedback



the factorial of non-negative integer n is written n! and is defined as follows: n!=n*(n-1)*(n-2)..

Answer / shanthimathi

The factorial of non-negative integer n is written n! and is
defined as follows:?
n! = n * (n – 1) * (n – 2) . …. .1 (for values of n greater
than or equal to 1).

and

n! = 1 (for n =0).

Perform the following:
a) Write a C program that reads a non-negative integer and
computes and prints its factorial.
b) Write a C program that estimates the value of the
mathematical constant e by using the formula:

e = 1 + 1/1! + 1/2! + 1/3! + …..
c) Write a C program that computes the value ex by using the
formula

ex= 1 + x/1! + x2/2! + x3/3! + …..

Answer:
a) int main()
{

int num;
long unsigned int factorial=1;

printf("Enter a number to compute factorial : ");
scanf("%d",&num);

for(int i=0;i<num;num--){
factorial *= num;
}

printf("The factorial is %d\n",factorial);
return 0;
}
//use upto num = 10 or 12 I guess

(b) For this

int main(){
int num = 3;
float e_value=1;
float int factorial;

for(int i=0;i<num;num--){
factorial = 1;
for(int j=num;j>0;j--){
factorial *= j;
}
e_value += 1/factorial;
}
printf("The e value is %f\n",e_value);
return 0;
}

(c) for this the one you can figure out now I hope

int main(){
int num=3;
float e_value = 1;
float factorial;
int x;

printf("enter value of x : ");
scanf("%d",&x);

for(int i=0;i<num;num--){
factorial = 1;
for(int j=num;j>0;j--){
factorial *= j;
}
e_value += (x*num)/factorial;
}
printf("The value of ex is : %f",e_value);
return 0;
}

Is This Answer Correct ?    35 Yes 11 No

the factorial of non-negative integer n is written n! and is defined as follows: n!=n*(n-1)*(n-2)..

Answer / dally

#include<stdio.h>
int main()
{
int i,n,sum =0;
printf("Enter value for n\n");
scanf("%d",&n);
sum = sum+1/fact(i);
printf("sum of Total result %d",sum);
}

int fact(int j)
{
int k =1;
if(k <= j)
fact = k*fact(--j);
return fact;
}

Is This Answer Correct ?    16 Yes 10 No

Post New Answer

More C Interview Questions

void main() { int a=1; printf("%d %d %d",a,++a,a++); } the output is supposed to be 1 2 2....but it is 3 3 1 this is due to calling conventions of C. if anyone can explain me how it happens?

7 Answers  


What do you mean by keywords in c?

0 Answers  


What is the best way to store flag values in a program?

0 Answers  


Can you define which header file to include at compile time?

0 Answers   Aspire, Infogain,


what is bit rate & baud rate? plz give wave forms

0 Answers  






I was asked to write a program in c which when executed displays how many no.of clients are connected to the server.

0 Answers  


C program to find frequency of each character in a text file?

6 Answers  


What is the proper way of these job Tell me about there full work

0 Answers   EDS,


Rapunzel walks into the forest of forgetfullness. She meets a Lion who lies on Monday Tuesdays and Wednesdays and meets a rabbit who lies on Thurs fridays and saturdays . On that day both say that "I lied yesterday". What day is it .

3 Answers   TCS,


1 232 34543 4567654 can anyone tell me how to slove this c question

6 Answers  


What do you mean by command line argument?

0 Answers   TCS,


write a program to display numbers from 1 to 10 and 10 to 1?

2 Answers  


Categories