ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
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!+....
 Question Submitted By :: Guest
I also faced this Question!!     Rank Answer Posted By  
 
  Re: 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
# 1
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 ?    8 Yes 3 No
Shanthimathi
 
  Re: 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
# 2
#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 ?    0 Yes 0 No
Dally
 
 
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
How can I prevent other programmers from violating encapsulation by seeing the private parts of my class?  1
Write code for initializing one dimentional and two dimentional array in a C Program? Deshaw5
hello friends what do u mean by BUS ERROR i got this error while i am doing my program in DATA STRUCTURES Wipro2
Is the following code legal? struct a { int x; struct a b; }  3
printf("%d",(printf("Hello")); What it returns? TCS23
marge linklist HCL1
write a “Hello World” program in “c” without using a semicolon?  3
disadvantages of realloc ? HCL1
Convert the following expression to postfix and prefix X $ Y Z - M + N + P / Q / (R + S)  2
What's the best way to declare and define global variables?  5
find a number whether it is even or odd without using any control structures and relational operators? Microsoft14
helllo sir give me some information of the basic information the c as printf ,scanf , %d ,%f and why is the main use of these.  3
what is the use of fflush() function?  1
write a function to find whether a string is palindrome or not and how many palindrome this string contain?  1
write a program to search for an element in a given array. If the array was found then display its position otherwise display appropriate message in c language  3
how to convert binary to decimal and decimal to binary in C lanaguage  4
how can i make a program with this kind of output.. Enter a number: 5 0 01 012 0123 01234 012345 01234 0123 012 01 0 Wipro3
write a program to check whether a given integer is a strong number or not? [Hint: 145=1!+4!+5! =1+24+120 =145]  4
write a program to sort the elements in a given array in c language  2
void main() { int s[4][2]={ {1234,56},{1212,33},{1434,80},{1312,78} }; int (*p)[2]; int i,j,*pint; for(i=0;i<=3;i++) { p=&s[i]; pint=p; printf("\n"); for(j=0;j<=1;j++) printf("%d",*(pint+j)); } } while running this program it shows a warning-suspicious pointer conversion ie pint=p; my que is why should we assign the value of p to pint again.why cant we use it directly as *(p+j)..but if i use like tat the o/p is garbage value..  1
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com