# C Program Calculate Factorial of a Number using Recursion

by Dinesh Thakur Category: C Programming (Pratical)

Consider the program given below, written using the top-down approach, that calculates the factorial of a given integer number using function fact defined in Example. Function fact is called in the main function from a printf function call and the int value returned by it is printed using the %d conversion specification.

Observe that the main function is defined first followed by the function fact, which is called before it is defined. Thus, we need to declare fact in the main function or before it. In the program given above, fact is declared before the main function. The program output is given below.

```#include<stdio.h>int fact(int);void main(){        int n,t;        clrscr();        printf("Enter any Number : ");        scanf("%d",& n);        t=fact(n);        printf("Factorial of %d is : %d",n,t);        getch();}        int fact(int a)      {               int p;               if(a==1)                        return(1);               else               {                        p=a*fact(a-1);                        return(p);               }      }
``` Dinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.
{"ft_lang_label":"__label__en","ft_lang_prob":0.83495283,"math_prob":0.960372,"size":1241,"snap":"2020-10-2020-16","text_gpt3_token_len":294,"char_repetition_ratio":0.12530315,"word_repetition_ratio":0.0,"special_character_ratio":0.24415794,"punctuation_ratio":0.17692308,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9784179,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,2,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-04-04T15:15:40Z\",\"WARC-Record-ID\":\"<urn:uuid:bc203140-e8ca-4fb1-a76d-84ff23cfd96a>\",\"Content-Length\":\"70541\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:a6119395-8efb-445d-a818-534819b9abf1>\",\"WARC-Concurrent-To\":\"<urn:uuid:9d504580-4dde-4956-9e5f-f9ba1d28e0d2>\",\"WARC-IP-Address\":\"216.194.173.231\",\"WARC-Target-URI\":\"http://ecomputernotes.com/c-program/write-a-program-to-calculate-factorial-of-a-number-using-recursion\",\"WARC-Payload-Digest\":\"sha1:AR7MLW3CCRTP2CWTAZNK5ROID7IWPIYX\",\"WARC-Block-Digest\":\"sha1:OLEK6X6S42CSQSWD2GMQ2U5Q5FK52BWA\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-16/CC-MAIN-2020-16_segments_1585370524043.56_warc_CC-MAIN-20200404134723-20200404164723-00456.warc.gz\"}"}