Assignment 3_Question 3:
Write a C program to list all the factorial numbers less than or equal
to an input number n.
A number N is called a factorial number if it is the factorial of a
positive integer. For example, the first few factorial numbers are
1, 2, 6, 24, 120, ...
*Note* - We do not list the factorial of 0.
Input
-----
A positive integer, say n.
Output
------
All factorial numbers less than or equal to n.
PROGRAM:
#include<stdio.h>
int factorial(int f)
{
if(f==1)
return 1;
else
return f*factorial(f-1);
}
int main()
{
int n,l=1,g=2;
scanf("%d",&n);
while(n>=l)
{
printf("%d ",l);
l=factorial(g);
g++;
};
return 0;
}
Disclaimer: Here you can find all nptel assignment solutions related to CS stream.These may help you for your assignment.The answers are only for verification.You cannot copy these directly from the post(code of conduct of NPTEL).These is not 100% correct solutions.
Can you please post Assignments for Week 4 and 5 as well. I am getting error every time. So would really appreciate your help.
ReplyDelete