0
Can any one help me why this code is running
3 odpowiedzi
+ 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.
+ 1
Thank you brother for answering me
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));