Write C program to find factorial of any number

Write C program to find factorial of any number


Introduction

Write C program to find factorial of any number


techstudy.org

Kindle Paperwhite High Resolution Display Tablet | Rs. 9999

Calculating power of a number using while loop


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <stdio.h>

int main()
{
    int num,i;
    long long fact=1;

    // Reading a number from user
    printf("Enter any number to calculate factorial: ");
    scanf("%d",&num);
    fact = 1;
    i = 1;

      //Run loop from 1 to number entered by user
    while(i <= num)
    {
        fact = fact * i;
        i++;
    }
     printf("Factorial of %d = %lld", num, fact);
 return 0;
}

Calculating power of a number using for loop



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>

int main()
{
    int i, num;
    long long fact=1;

    // Reading a number from user
    printf("Enter any number to calculate factorial: ");
    scanf("%d", &num);

    //Run loop from 1 to number entered by user
    for(i=1; i<=num; i++)
    {
        fact = fact * i;
    }

    printf("Factorial of %d = %lld", num, fact);

    return 0;
}

Result

C language

     





Related Topics


Responses




Popular Posts

Facebook

Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer and technology lovers. http://www.techstudy.org/.