Write a program to compute the following
1!+2!+...n!
Answers were Sorted based on User's Feedback
Answer / fhghg
#include<stdio.h>
int n_fact(int n);
void main()
{
int n,res=0;
printf("ENTER A NUMBER:-");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
res+=n_fact(n);
}
printf("%d",res);
}
int n_fact(n)
{
int result;
if(n=0)
result=1;
else
result=n*n_fact(n-1);
return(result);
}
| Is This Answer Correct ? | 8 Yes | 2 No |
#include<stdio.h>
#include<conio.h>
long factorial(int,long);
void main()
{
int i,m;
long sum=0,k=1;
clrscr();
printf("enter ur no. of terms :");
scanf("%d",&m);
i=1;
while(i<=m)
{
k=factorial(i,k);
sum+=k;
i++;
}
printf("the sum is : %ld",sum);
getch();
}
int factorial(int i,long k)
{
return (i*k);
}
hope this also correct...
thank u
| Is This Answer Correct ? | 3 Yes | 0 No |
Answer / yamuna
/* A.Yamuna III BSC CS L.R.G. College , Tirupur*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a,n;
int sum=1;
int total=0;
clrscr();
printf("Enter the number :");
scanf("%d",&n);
for(a=1;a<=n;a++)
{
for(int i=1;i<=a;i++)
{
sum=sum*i;
}
total=total+sum;
sum=1;
}
printf("The factorial is :%d",total);
getch();
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / ashish
#include<stdio.h>
int n_fact(int n);
void main()
{
int n,res;
printf("ENTER A NUMBER:-");
scanf("%d",&n);
res=n_fact(n);
printf("%d",res);
}
int n_fact(n)
{
int result;
if(n=0)
result=1;
else
result=n*n_fact(n-1);
return(result);
}
| Is This Answer Correct ? | 5 Yes | 6 No |
How to find a missed value, if you want to store 100 values in a 99 sized array?
Explain the term printf() and scanf() used in c language?
Write a program to print distinct words in an input along with their count in input in decreasing order of their count..
What is static identifier?
write a program to create a sparse matrix using dynamic memory allocation.
C program to read the integer and calculate sum and average using single dimensional array
Is null always defined as 0(zero)?
what is the use of ~ in c lang?????
How will you divide two numbers in a MACRO?
Devise a program that inputs a 3 digit number n and finds out whether the number is prime or not. Find out its factors.
for(i=1;i>0;i++); printf("i=%d",i); what will be the answer????
Why is a semicolon (;) put at the end of every program statement?