Computer Science, asked by Uttar7805, 1 year ago

C program to calculate the factorial of a non negative integer

Answers

Answered by spidy298
2
#include<conio.h>
#include<stdio.h>
void main() {
int c, n, fact = 1;
  printf("Enter a number \n");
scanf("%d", &n);  
for (c = 1; c <= n; c++)
fact = fact * c;
 printf("Factorial of %d = %d\n", n, fact);  
}
Answered by aditijaink283
0

Answer:

The answer to the given question is explained in the explanation.

Explanation:

The sum of all integers from 1 to N is known as the factorial of the number N. The definition of factorial of 0 is 1. As the first command line parameter, the program will receive the nonnegative integer N. We must prepare the output as an integer and write it to stdout without including any other text. Assume that the input integer will not be larger than the maximum integer that may be stored in a variable of the int type.

#include <stdio.h>

#include <stdlib.h>

If n == 0,

int fact(int n)

returns 1;

else

int ans = 1;

int (I for I = 1; I = n; I++)

(ans = ans * I)

returns ans;

char* argv[],

int argc,

int main()

In case (argc == 1)

No command line arguments are present. Please provide them before continuing.

else

Integer I n, and ans; for I = 1, I argc, and i++)

Printf ("percent dn", ans);

return 0;

n = atoi(argv[i]);

ans = fact(n);

#SPJ2

Similar questions