Â
In this, we are going to see Functions, the program is based on function which Calculates, Profit or Loss.
The code given below can be used for TURBO C++ Compiler:-
#include<iostream.h>
#include<conio.h>
// creating factorial function
int factorial()
{
clrscr();
int n, i, fact = 1;
cout << "Enter the value of n \n";
cin >> n;
for (i = 1; i <= n; i++)
{
fact = fact * i;
}
cout << fact;
return fact;
}
void main()
{
factorial();
getch();
}
The code given below can be used for g++/gcc Compiler:-
#include<iostream>
using namespace std;
// creating factorial function
int factorial()
{
int n, i, fact = 1;
cout << "Enter the value of n \n";
cin >> n;
for (i = 1; i <= n; i++)
{
fact = fact * i;
}
cout << fact;
return fact;
}
int main()
{
factorial();
return 0;
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP