Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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!+....

Answer Posted / 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 ?    36 Yes 11 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between if else and switchstatement

1842


Can you write a programmer for FACTORIAL using recursion?

985


How do you view the path?

1076


What are the different categories of functions in c?

1082


What is function prototype in c language?

983


Write a code to generate divisors of an integer?

1008


What are different types of operators?

991


What is structure in c definition?

984


What is nested structure with example?

1012


What is the collection of communication lines and routers called?

1054


How do we print only part of a string in c?

974


Why can arithmetic operations not be performed on void pointers?

982


Explain what does the function toupper() do?

1006


Write a Program to accept different goods with the number, price and date of purchase and display them

6146


What kind of structure is a house?

994