C++ program to calculate factorial of a number using loop.

#include<iostream.h>
#include<conio.h>
int main(){
long int fact=1;
int n;
clrscr();
cout<<"Enter a Positive Integer Number"<<endl;
cin>>n;
if(n>0){
for(int i=1;i<=n;i++){
fact=fact*i;
}
cout<<"Factorial of "<<n<<" = "<<fact<<endl;
}
else{
cout<<"Wrong Number Inserted"<<endl;
}
getch();
return 1;
}

No comments:

Post a Comment