Attachments
-
You do not have permission to view the full content of this post. Log in or register now.
#include <stdio.h>
int main()
{
int n,o;
unsigned long factorial=1;
printf("Enter an integer: ");
scanf("%d", &n);
o = n;
if (n < 0)
{
printf("Invalid number!");
}
else
{
while (n > 0)
{
factorial = factorial * n;
n = n - 1;
}
printf("\n%d! = %lu", o, factorial);
}
getch();
return 0;
}
C:#include <stdio.h> int main() { int n,o; unsigned long factorial=1; printf("Enter an integer: "); scanf("%d", &n); o = n; if (n < 0) { printf("Invalid number!"); } else { while (n > 0) { factorial = factorial * n; n = n - 1; } printf("\n%d! = %lu", o, factorial); } getch(); return 0; }
It looks familiar, paki check kung gagana yung code.
#include <stdio.h>
int main() {
int num1,prod;
printf("enter number \n");
scanf("%d",&num1);
int num2 = num1;
if(num1<0){
printf("%d! = Invalid",num2);
}else{
for(int i=num1-1; i>=1; i--){
prod = num1*i;
num1 = prod;
}
printf("%d! = %d",num2,num1);
}
return 0;
}