Â
In this, we are going to see for loop, the program is based on for loop which basically, finds the factorial of any number specified by the user.
The code given below can be used for TURBO C++ Compiler:-
#include<iostream.h>
#include<conio.h>
void main()
{
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;
getch();
}
The code given below can be used for g++/gcc Compiler:-
#include<iostream>
using namespace std;
int main()
{
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 0;
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP