Factorial of a Number in C++ - Learn Engineering

All the news and updates relevant to Engineering. You can also Write a post here

Breaking

Friday, June 12, 2020

Factorial of a Number in C++


C++ PROGRAM TO FIND THE FACTORIAL OF A NUMBER


Sample Test Case    :    Enter a Number : 5

Sample Test Case    :    Factorial of 5 is 120


CODE


#include<stdio.h>
int main()
{
    int num,fact=1;
    cout<<"Enter a Number :";
    cin>>num;
    for(int a=1;a<=num;a++)
    {
        factorial=fact*a;
    }
    cout<<"Factorial of "<<num<<" is"<<fact;
    return 0;
}

No comments:

Post a Comment