Factorial

Factorial
Factorial
Factorial

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn C programming concepts. You can learn C language at your own speed and time. One can learn concepts of C language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Write a C program to Factorial

PROGRAM: Factorial

/* Calculate factorial using while loop */
#include<stdio.h>
int main()
{
    int a,f,i;
    printf("Enter a number: ");
    scanf("%d",&a);
    f=1;
    i=1;
    while(i<=a)
    {
        f = f * i;
        i++;
    }
    printf("Factorial: %d",f);
 return 0;
}

--------------------------------------------------------------

/* Calculate factorial using for loop */
#include<stdio.h>
int main()
{
    int a,f,i;
    printf("Enter a number: ");
    scanf("%d",&a);
    f=1;
    for(i=1;i<=a;i++)
        f = f * i;
    printf("Factorial: %d",f);
 return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *