مثال برمجي 5 : computes the factorial
- 2020-10-29
توصيف
السؤال من كورس ال Programming الخاص بي
Write a program that reads a positive integer and computes the factorial
الجواب
/************************************************************************************
Name : ex12.c
Author : Mohamed Elsayed
Description : Assignment 1 - Ex 12
***********************************************************************************/
#include
int main()
{
int input;
long long fact = 1;
int i;
printf("Please enter the required number : ");
scanf("%d",&input);
/* Loop to calcuate the factorial for example (5! = 5 * 4 * 3 * 2 * 1) */
for(i=1;i<=input;i++)
{
fact = fact * i;
}
printf("\nfactorial of %d is: %ld",input,fact);
return 0;
}
لمزيد من التفاصيل يرجى التواصل معي