How to make a factorial Program in C++?
This program calculates the the factorial of an integer number entered by the user. The function uses for loop to calculate the factorial and returns the number. Program terminates if a non integer number is entered. This C language program uses for loop in just a single statement to calculates the factorial of integer number.
#include<conio.h>
#include<conio.h>
#include<iostream.h>
void main(void)
{
int a=1,n,fn=1; //Variable Decileration
clrscr(); // // For Clear Screen
cout<<"Enter Your Number = "; //For Geting any OutPut
cin>>n; //For Geting any Input
for(a=1; a<=n; a++) //Looping
{
fn=fn*a;
}
cout<<fn; //For Out put of Factorial Program
getch(); //For Stop a Screen for a while
untill you press any key
}
Comments
Post a Comment