- 1

write a program that calculates N! if N=5 thenN!=5*4*3*2*1.

using for loop

29th Apr 2017, 11:45 AM
Zeyad Sharo
Zeyad Sharo - avatar
8 Respuestas
+ 13
function factorialOf(n){ var eq=n; for (;n>1;){ n--; eq *=n; } return eq; } sorry, written in JavaScript. But how ever the most important is the ALGORITHM. Language not very important, But without algorithm, CODING is NOTHING, also include math.
29th Apr 2017, 11:49 AM
Immanuel
Immanuel - avatar
29th Apr 2017, 12:49 PM
Mayur Chaudhari
Mayur Chaudhari - avatar
+ 6
int f = 1,i,n; cout<<"Enter number"; cin>>n; for(i=n;i>0;i--) { f = f * i; } cout<<f;
29th Apr 2017, 12:50 PM
Mayur Chaudhari
Mayur Chaudhari - avatar
+ 2
sorry it was written in c# :)
29th Apr 2017, 12:05 PM
Mohamed Khalil NASRALLAH
Mohamed Khalil NASRALLAH - avatar
+ 1
I did it in Java.Check this out.You can try in c++,logic will be same☺☺ package Java1; import java.util.*; public class Vool2 { public static void main(String[] args) { int N=1; Scanner input=new Scanner(System.in); System.out.println("Now enter a value to do factorial" ); int u=input.nextInt(); for(int i=u;i>0;i--) { N=i*N; } System.out.println(N); } }
29th Apr 2017, 12:18 PM
Saikat Mukherjee
Saikat Mukherjee - avatar
+ 1
unsigned n = 5, fact = 1; for(unsigned i = n; i; --i) fact *= i;
29th Apr 2017, 12:46 PM
Bebida Roja
Bebida Roja - avatar
0
i need The solution by c++ program the answer above Not clear
29th Apr 2017, 11:52 AM
Zeyad Sharo
Zeyad Sharo - avatar
- 1
int f = 1; for(int i =1; i<=n;i++) f=f*i; cout << f;
29th Apr 2017, 11:48 AM
Hitesh Datt
Hitesh Datt - avatar