FACTORIAL NUMBERS

          This time I will explain a C language program that is on the factorial numbers . Numbers factorial is the product of all the numbers is less than or equal to n. factorial denoted by "!", if written "n!" is pronounced "n factorial"
For example:
0! = 1
1! = 1
2! = 1 x 2 = 2
3! = 1 x 2 x 3 = 6
4! = 1 x 2 x 3 x 4 = 24
etc.
             program's source code can be seen below:

#include<stdio.h>
#include<stdlib.h>
int main() {
printf("       [**********************]\n"); printf("  ---[** CALCULATE FACTORIAL **] ---\n");
printf("       [**********************]\n");
int n,i;
int hasil;
int x=1;
printf("   enter numbers n!: ");
scanf("    %d", &n);
printf("    n! of %d is ", n);
for(i=n ; i>0 ; i--) {
x = x * i;
printf("%d", i);
if(i>1) {
printf(" x ");
} else {
printf(" = ");
}
}
printf("%d", x);
return 0;
}

compiler results:


            Thanks for visiting, please your comment and share ^-'

No comments:

Post a Comment