In this program we will declare an integer and ask user to enter its value. Then we will pass that integer to function where we will find factorial using for loop.
Program:
// Program By http://solutionscpp.blogspot.com// Author Mansoor Ahmed
// GMail ID: secguy000@gmail.com
#include<iostream>
using namespace std;
int fact(int n); //function prototype
int main()
{
int n=0, result=0;
cout<<"Enter Number: ";
cin>>n;
result=fact(n);
cout<<"Factorial of " <<n <<" is: " <<result <<endl;
}
int fact(int n) //function definition
{
int f=1;
for(int i=1; i<=n; i++)
{
f=f*i;
}
return f;
}
This code is helpful but I want some Example of C++ Programs;
ReplyDeletePrint Star pattern in C++
Print number pattern in C++
Factorial Program in C++
This is stunning! I am passed up the nature with this astounding.I've perused a lot of articles, financial firms one of the best ones that I've perused. Keep on providing more articles this way.solve your afp problems
ReplyDeleteI found nice article in your blog.thank you for useful info
ReplyDelete.
ReplyDeletenice article for beginners.thank you.
c++ tutorial
java tutorial