Program that calculate the factorial value of any number by using functions

Program that calculate the factorial value using functionsProgram that calculate the factorial value of any number by using functions

Object: Write a function to calculate the factorial value of any integer entered through the keyboard. C++ projects for beginners with source code

Code:

#include<iostream>
#include<conio.h>
using namespace std;

int fac(int num);

void main()
{
int nu;
cout<<“\nEnter Any Number: “;
cin>>nu;
cout<<fac(nu);
getch();
}
int fac(int num)
{
int i,fact=1;
for(i=num;i>=1;i–)
{
fact=fact*i;
}
cout<<“\nFactorial of given Number is: “;
return fact;
}

#include<iostream>
#include<conio.h>
using namespace std;

int fac(int num);

void main()
{
	int nu;
	cout<<"\nEnter Any Number: ";
	cin>>nu;
	cout<<fac(nu);
	getch();
}
int fac(int num)
{
	int i,fact=1;
	for(i=num;i>=1;i--)
	{
		fact=fact*i;
	}
	cout<<"\nFactorial of given Number is: ";
	return fact;
}

Output:

Program that calculate the factorial value of any number by using functions

1 thought on “Program that calculate the factorial value of any number by using functions”

  1. Pingback: C++ projects for beginners with source code - Codeboks

Leave a Comment

Your email address will not be published.