a) Write a program that reads a nonnegative integer and computes and prints its factorial.
#include <stdio.h>
int main(){
int fact, result = 1, i;
printf("Masukan angka non negative: ");
scanf("%d", &fact);
if(fact>0){
for(i=fact; i>=1; i--){
result *= i;
}
printf("Hasil dari %d! adalah %d.\n", fact, result);
}
system("pause");
}
0 komentar:
Posting Komentar
Click to see the code!
To insert emoticon you must added at least one space before the code.