/* Calculate factorial using while loop */
#include<stdio.h>
int main()
{
int a,f,i;
printf("Enter a number: ");
scanf("%d",&a);
f=1;
i=1;
while(i<=a)
{
f = f * i;
i++;
}
printf("Factorial: %d",f);
return 0;
}
--------------------------------------------------------------
/* Calculate factorial using for loop */
#include<stdio.h>
int main()
{
int a,f,i;
printf("Enter a number: ");
scanf("%d",&a);
f=1;
for(i=1;i<=a;i++)
f = f * i;
printf("Factorial: %d",f);
return 0;
}
Factorial
Subscribe to:
Post Comments (Atom)
For loop wala prog chal hi nhi rha laptop per ..value le rha hai but factorail calculate ni kr pa rha..
ReplyDeleteuse & in scanf function
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteFactorial of a number
ReplyDeleteHey good suggestions also check for
fresh2refresh
veewom
scholarsoul
hackerrank (practice)
leetcode (practice)