30th Nov 2023, 4:12 PM
Viraj Yadav
Viraj Yadav - avatar
3 Respostas
+ 2
Hi Viraj , You used if else if statement So, In this statement if any condition will be true then it will never check the other conditions. Talking about your program ,So If I entered no. 5 it shows "Enter the number0". why it shows this bcoz it satisfied else condition that's why it shows "Enter the number0". Actually ,You need to change some condition then your program will work . The solution of your program is given below: #include <stdio.h> int main() { int n,fact=1; printf("Enter the number\n"); scanf("%d",&n); while(n>0) { fact=fact*n; n--; } printf("The factorial of the no.is:%d",fact); return 0; } I hope I answered your question.
30th Nov 2023, 4:52 PM
Ayush Raj
+ 1
Thank you brother for answering me
30th Nov 2023, 5:33 PM
Viraj Yadav
Viraj Yadav - avatar
0
this give u the factorial !5=120 u can do it like this int fact(int x){ if(x<=1) return 1; else return x*fact(x-1); } printf("%d",fact(5));
1st Dec 2023, 7:05 PM
Med Yassine
Med Yassine - avatar