Example of while loop Write a C program to find the factorial of a number, where the number is entered by user. (Hints: factorial of n = 1*2*3*...*n

Sunday, May 10, 2015

/*C program to demonstrate the working of while loop*/
#include <stdio.h>
     int main(){
     int number,factorial;
     printf("Enter a number.\n");
     scanf("%d",&number);
     factorial=1;
     while (number>0){      /* while loop continues util test condition number>0 is true */
           factorial=factorial*number;
           --number;
}
printf("Factorial=%d",factorial);
return 0;
}
Output
Enter a number.
5
Factorial=120

1 comments:

felisha green said...

Are you willing to know who your spouse really is, if your spouse is cheating just contact cybergoldenhacker he is good at hacking into cell phones,changing school grades and many more this great hacker has also worked for me and i got results of spouse whats-app messages,call logs, text messages, viber,kik, Facebook, emails. deleted text messages and many more this hacker is very fast cheap and affordable he has never disappointed me for once contact him if you have any form of hacking problem am sure he will help you THANK YOU.
contact: cybergoldenhacker at gmail dot com

Post a Comment