Computer Science, asked by nayeemjannatun00090, 6 months ago

Develop a program which calculate the factorial n! = 1*2*... ...*n and output the result to the screen.

n is defined by user input.



Input Specification:

Input a positive integer. The integer are no more than 1000.



Output Specification:

For each test case, print in a line the value of n!.



Sample Input: 5 Sample Output: 120

Sample Input: 1 Sample Output: 1

Answers

Answered by Anonymous
3

Answer:

#include <stdio.h> int main() { int kases; scanf("%d", &kases); int kase; for(kase = 1; kase <= kases; kase++) { int N; scanf("%d", &N); int result[1000]; result[0] = 1; int length = 1, i, j, temp, carry = 0; for(i = 2; i <= N; i++) { for(j = 0; j < length; j++) { temp = carry + result[j] * i; carry = temp / 10; result[j] = temp % 10; } while(carry) { result[j] = carry % 10; carry /= 10; j++; } length = j; } for(int i = length - 1; i >= 0; i--){ printf("%d", result[i]); } printf("\n"); } return 0; }

Similar questions