/* 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;
}
Related Post:
Calculate factorial using for loop
http://cbasicprogram.blogspot.in/2012/02/calculate-factorial-using-for-loop.html
#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;
}
Related Post:
Calculate factorial using for loop
http://cbasicprogram.blogspot.in/2012/02/calculate-factorial-using-for-loop.html
osum work done by using only while loop
ReplyDeleteAttention everyone, the file provided above is not working. I have been looking for the working file and finally found it.
Delete✔️Click Here To Download http://gestyy.com/e0GAyS
✔️Click Here To Download
✔️Click Here To Download http://exe.io/XONVsO6l
✔️Click Here To Download
✔️Click Here To Download
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
Mn.
..
.
.
.
..
.
.
.
.
.
.
.
.
.
.
..
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.xz
.
.sdcccxxx
superb
ReplyDelete#include
ReplyDelete#include
#include
int main()
{
int a,b=1;
printf("Enter a number.");
scanf("%d",&a);
while(a>1)
{
b=a*b;
a=a-1;
}
printf("The answer is %d",b);
return 0;
}
But you have not initiated a for the loop. the user has to enter the vaue of a ?
DeleteGood
DeleteWhy does it gives -25216 if we input 8??
ReplyDeletebecause int range is -32,768 to 32,767, try this program with long variables
Deletehttp://codepad.org/0QF7Czjm
Sir y hve u taken f=1?
ReplyDeletebecause we are multiplying, if we make it 0,every value would be 0.
DeleteThe program lacks one thing..if we give 0 then it would not return its factorial as its factorial is zero and it would return zero..the issue can be fixed by a combination of else with while loop..
ReplyDeletehttps://maytinhtrananh.vn/sua-may-tinh-may-in.html
ReplyDeletehttps://phalebinhminh.com
Nice....
ReplyDeleteI got what I was finding....
Thanks..