توصيف

السؤال من كورس ال 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;
}

 

لمزيد من التفاصيل يرجى التواصل معي

هل كان المحتوى مفيد؟

التعليقات

لاضافة سؤال أو تعليق على المشاركة يتوجب عليك تسجيل الدخول
تسجيل الدخول
محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...