# Factorial nos less than N

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. please see the code i have uploaded below. and help me please. thanks a lot. https://code.sololearn.com/c4PrwXX2Dehe/?ref=app John Wells

9/19/2018 3:39:51 PM

Nilutpol Kashyap12 Answers

New Answeruse do while loop, condition will be same #include<stdio.h> int fact(int n) { int ans = 1; for(int i = 0; i < n; i++) { ans = ans * (i + 1); } return ans; } int main() { int N, n = 1, f; scanf("%d",&N); do { f = fact(n); printf("%d\t",f); n = n + 1; }while(f < n); return 0; }

Or initialize f, if you want n=5 to only 1, 2, & 6. If you want to skip 6, add if (f<N) around printf.

John Wells thank you sir. I initialized f= 0 and added an if. (f>N) statement before break. it's working great. thanks again

nAutAxH AhmAd thank you. but using do while it would simply print one extra factorial no. I have sorted out my mistake. thank you very much for your time, help and patience. ☺️

Uninitialized variables have a value of whatever is left in memory, until you assign something to them. It had to be higher than 5.

nAutAxH AhmAd I have corrected it but still it is showing one factorial more. please help me

John Wells its not working. I have included an if statement inside main. it's working for inputs like 25 & 30 etc but it is not working for values like 4, 5, 6. can u pls look into it.

John Wells sir can you please explain in more details. I am not able to understand.