Function Main
Declare Integer n
Declare Integer i
Declare Integer fact
Assign fact = 1
Output "Enter an integer: "
Input n
If (n<0)
Output "Error! Factorial of a negative number doesn't exist."
Else
For i = 1 to n
Assign fact = fact * i
End
Output "Factorial is " &fact
End
End
#include <stdio.h>
int main() {
int n, i;
int fact = 1;
printf("Enter an integer: ");
scanf("%d", &n);
if (n < 0)
printf("Error! Factorial of a negative number doesn't exist.");
else {
for (i = 1; i <= n; ++i) {
fact *= i;
}
printf("Factorial is %d",fact);
}
return 0;
}
I am Md. Anisur Rahman. I have completed Cyber Security for MSCSE at United International University in 2022.I have completed PGDIT from IIT, Jahangirnagar University in 2020. I'm a Head of IT at Programming24 School.
View all posts by Md. Anisur Rahman