- 1
write a program that calculates N! if N=5 thenN!=5*4*3*2*1.
using for loop
8 Réponses
+ 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.
+ 6
int f = 1,i,n;
cout<<"Enter number";
cin>>n;
for(i=n;i>0;i--)
{
f = f * i;
}
cout<<f;
+ 2
sorry it was written in c# :)
+ 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);
}
}
+ 1
unsigned n = 5, fact = 1;
for(unsigned i = n; i; --i)
fact *= i;
0
i need The solution by c++ program
the answer above Not clear
- 1
int f = 1;
for(int i =1; i<=n;i++)
f=f*i;
cout << f;