C Language Tutorials by Ghulam Murtaza Dahar - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

1*2*3*...*n

/*C program to demonstrate the working of while loop*/

index-28_1.jpg

#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;

}