Q1. The following program generates the sum of the first n numbers.
#include <stdio.h>
main()
{
int n;
int i = 0;
int sum = 0;
printf("Please enter a positive integer: ");
scanf("%d", &n);
while (i < n) sum+=++i;
printf("the sum of the first %d numbers is %d\n", n, sum);
}
(a) Convert the program to calculate the factorial of n, which is the product of the first n numbers, and obtain the values of the factorial for the following inputs:
a. n = 3 n! = _______________
b. n = 12 n! = _______________
c. n = 13 n! = _______________
d. n = 20 n! = _______________
e. n = 23 n! = _______________
f. n = 43, n! = _______________
(2 points)
(b) If you see a problem with the results, what is the cause?
(1 point)
(c) Modify the program so that if the answer is correct, the program outputs the result, otherwise it outputs the message "Error: cannot compute factorial for this number". Obtain the output for the following inputs:
a. n = 3 n! = _______________
b. n = 12 n! = _______________
c. n = 13 n! = _______________
d. n = 20 n! = _______________
e. n = 23 n! = _______________
f. n = 43, n! = _______________
(2 points)
Arkadaşlar cevabı arıyorum sınavdayım HELP ME