0% found this document useful (0 votes)
33 views

Program

The document provides an algorithm to find the factorial of a number. The algorithm uses variables to store the input number and the calculated factorial, and a for loop to multiply the input number by all integers from 1 to itself. The code implements this algorithm by prompting the user for a number, initializing the variables, using a for loop to calculate the factorial, and outputting the result.

Uploaded by

tanzeel hayyat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Program

The document provides an algorithm to find the factorial of a number. The algorithm uses variables to store the input number and the calculated factorial, and a for loop to multiply the input number by all integers from 1 to itself. The code implements this algorithm by prompting the user for a number, initializing the variables, using a for loop to calculate the factorial, and outputting the result.

Uploaded by

tanzeel hayyat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

qwertyuiopasdfghjklzxcvbnmqwertyui

opasdfghjklzxcvbnmqwertyuiopasdfgh
jklzxcvbnmqwertyuiopasdfghjklzxcvb
nmqwertyuiopasdfghjklzxcvbnmqwer
tyuiopasdfghjklzxcvbnmqwertyuiopas
dfghjklzxcvbnmqwertyuiopasdfghjklzx
Data Structure and Algorithm

cvbnmqwertyuiopasdfghjklzxcvbnmq
wertyuiopasdfghjklzxcvbnmqwertyuio
pasdfghjklzxcvbnmqwertyuiopasdfghj
klzxcvbnmqwertyuiopasdfghjklzxcvbn
mqwertyuiopasdfghjklzxcvbnmqwerty
uiopasdfghjklzxcvbnmqwertyuiopasdf
ghjklzxcvbnmqwertyuiopasdfghjklzxc
vbnmqwertyuiopasdfghjklzxcvbnmrty
uiopasdfghjklzxcvbnmqwertyuiopasdf
ghjklzxcvbnmqwertyuiopasdfghjklzxc
Write a algorithm to find the factorial of a no.

 Algorithm:

Start
1. First of all take variables of integer type i and n.
2. Now take a variable of integer type fac and set it as fac = 1.
3. Now initialize i as i= 1 and set it to i<=n.
4. Now set fac = fac*i.
5. And store the value in fac.
End.

Code:
#include <iostream>

using namespace std;

int main() {

int i, n, fac=1;

cout<<"Enter a positive integer:";

cin>>n;

for (i = 1; i <= n; ++i)

{ fac= fac*i; }

cout<< "Factorial of "<<n<<" = "<<fac;}


Output:

You might also like