Write a C C++ program to find factorial of given number

 

Flowchart

Factorial of given number flowchart

 

Coding in C

#include<stdio.h>
int main()
{
int num,c=1,res=1;
printf(“Enter a number: “);
scanf(“%d”,&num);
while(c<=num)
{
res=res*c;
c++;
}
printf(“Factorial = %d”,res);
return 0;
}

 

Coding in C++

#include<iostream>
using namespace std;
int main()
{
int num,c=1,res=1;
cout<<“Enter a number: “;
cin>>num;
while(c<=num)
{
res=res*c;
c++;
}
cout<<“Factorial = “<<res;
return 0;
}

 

Output

Factorial of given number output

 

Published by

admin

I am a computer teacher, programmer and web developer