+ 4
How can I find factorial of 6?
#include <iostream> using namespace std; int main() { int num=0; while(num<=6){ cout<<num<<endl; num+=1; } return 0; }
13 Answers
+ 9
First declare an integer with value 1.And inside the `while` loop multiply that variable to the num and then increament the num by 1.So it will run until the num value is smaller than 6.
Read the below example :-
https://code.sololearn.com/cFEp5X818DUe/?ref=app
+ 4
I will try to give you explanation step by step
https://code.sololearn.com/cFEp5X818DUe/?ref=app
1>Firstly, I have created two integers that is `num` and `fac` and set their value by 1.
2>Then, I set up a `while` loop that will run until the `num` reach 6.That means it will run from 1 to 6.The numbers are 1,2,3,4,5,6
3>Inside `while` loop I multiplied the `fac` integer with `num` and `num` has values from 1 to 6.That means the code multiply in this way 1*2*3*4*5*6.And it's result is 720.
4>Then I used `num++;` to increment the value of `num` by 1.
5>Finally, I output the value of fac and the value is 720.
+ 3
Solution:-
int x=6;
int y=1;
while(x!=0)
{
y*=x;
x--;
}
cout<<"Factorial of 6: "<<y;
+ 2
To find the factorial of 6 in C++, you can modify your code to calculate it. Here's an example using your existing code:
#include <iostream>
using namespace std;
int main() {
int num = 6;
int factorial = 1;
while (num > 0) {
factorial *= num;
num--;
}
cout << "Factorial of 6 is: " << factorial << endl;
return 0;
}
This code initializes factorial to 1 and then multiplies it by the current value of num in each iteration of the loop. Finally, it prints the result, which should be the factorial of 6.
+ 1
Can you please explain this how did it done
+ 1
Haram Abbas use long unsigned int to hold bigger values
https://code.sololearn.com/cgRXgaoY9UXk/?ref=app
+ 1
you could do something like:
int num=6;
int res=1;
while(num!=0){
res*=num;
num--;
}
cout<<"Factorial 6: "<<res;
+ 1
dfg
+ 1
ۧÙŰłÙۧÙ
ŰčÙÙÙÙ
0
#include<iostream.h>
#include<conio.h>
void main()
{
int n,i=1;
clrscr();
cout<<"\n enter n to compute n fact :";
cin>>n;
long fact=1;
while(i<=n)
{
fact=fact*i;
i++;
}
cout <<"\n Factorial of n :"<<fact;
getch();
}
By using this code u can find factorial of any number. And keep in mind , while finding factorial use datatype long because long can store -2^31 to 2^31-1 space.
0
I want to learn
0
#python code for factorial program
n=int(input())
f=1
for I in range(1,n+1,1):
f=f*i
print(f)