Write a program to calculate the factorial of an integer entered by the user. For example N = 7 the factorial of 7 equal to 1* 2 * 3 * 4 * 5 * 6 * 7 = 5040.
******** In Algorithm ********
Algorithm Variables i,F,N: integers Begin F ← 1 write("Enter a positive integer :")
read (N) for i from 1 to N F ← F * i next write("the factorial of",N,"is:" F) End Result ===> Enter a positive integer : 6 the factorial of 6 is : 720
******** In C ********
#include <stdio.h> int main(){ int N,F=1,i; printf("Enter a positive integer:"); scanf("%d",&N); for(i=1;i<=N;i++) F = F * i ; printf("the factorial of %d is: %d",N,F); return 0; }
******** In C++ ********
#include <iostream>
using namespace std;
int main(){
int N, F=1, i ;
cout<<"Enter a positive integer :" ;
cin>>N;
for(i=1 ; i<=N ; i++)
F = F * i ;
cout<<"the factorial of"<<N<<"is"<<F ;
return 0;
}
******** In JAVA ********
import java.util.Scanner;
class Main {
public static void main(String[] args){
int i,F=1,N;
Scanner sc = new Scanner (System.in);
System.out.print("Enter N:");
N = sc.nextInt();
for(i=1;i<=N;i++)
F = F * i;
System.out.print("the factorial of"+N+" est "+F);
}
}
******** In C# ********
using System;
public class Ex29 {
public static void Main(string[] args)
{ int i,F=1,N;
Console.Write("Enter N:");
N=int.Parse(System.Console.ReadLine());
for(i=1;i<=N;i++)
F = F * i;
Console.Write("the factorial of"+N+" est "+F);
}
}
class Main {
public static void main(String[] args){
int i,F=1,N;
Scanner sc = new Scanner (System.in);
System.out.print("Enter N:");
N = sc.nextInt();
for(i=1;i<=N;i++)
F = F * i;
System.out.print("the factorial of"+N+" est "+F);
}
}
using System;
public class Ex29 {
public static void Main(string[] args)
{ int i,F=1,N;
Console.Write("Enter N:");
N=int.Parse(System.Console.ReadLine());
for(i=1;i<=N;i++)
F = F * i;
Console.Write("the factorial of"+N+" est "+F);
}
}