مثال برمجي 5 : computes the factorial
-
2020-04-15
- | drMohammedAbdElrahem
- | مشاهدات: 681
السؤال من كورس ال 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;
}
لمزيد من التفاصيل يرجى التواصل معي
هذه المادة الدراسية هي ضمن مكتبة
أمثلة برامج Cقد يهمك أيضاً بمادة
التعليقات
لا يوجد تعليقات
لاضافة سؤال او تعليق على المشاركة يتوجب عليك تسجيل الدخول
تسجيل الدخول
تسجيل الدخول