Monday, February 10, 2020

find factorial of given a number in C++ / Java Program?

Image result for factorial of  given a number concept?
 
 

Factorial of  given a number in C++ Program

 
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,f=1,a;
cout<<"\nEnter any number :";
cin>>n;
for(a=1;a<=n;a++)
{
cout<<a<<"\n";
f=f*a;
a++;
}
cout<<"factorial is :"<<f;
getch();
}

Factorial of  given a number in Java Program


 import java.util.Scanner;
class factory
{
public static void main(String []args)
{
int n,f=1,a;
Scanner  obj=new Scanner(System.in);
System.out.println("  Enter a number :"  );
n=obj.nextInt();
for(a=1;a<=n;a++)
{
System.out.println( a);
System.out.println("  "  );
f=f*a;
a++;
}
System.out.println("   Factorial is  :"   +f);
}
}

No comments:

Post a Comment