Fsc Online | Online Notes, Educational News & Latest Government Job UpdatesFsc Online | Online Notes, Educational News & Latest Government Job Updates
  • Home
  • Notes
    • Online Courses
      • 12th Class
      • 11th Class
      • 10th Class
      • 9th Class
  • Jobs
    • PPSC Jobs
    • SPSC Jobs
    • Punjab Police Jobs
  • Education News
  • E-Books
    • Punjab Text Book (PTB)
  • Model Papers
  • Results
  • Admissions
  • Colleges
  • More
    • Paper Schemes
    • Date Sheets
    • Guess Papers
    • Roll No Slips
Facebook Twitter
Trending
  • NADRA Islamabad Announced Latest April Jobs 2024
  • TEVTA Sargodha Announced Instructor / Clerk Jobs 2024
  • BPSC Announced Latest Jobs Through Advertisement no. 03/2024
  • All Subjects 12th Class Paper Scheme 2024 | Punjab Board
  • 12th Class Computer Science Paper Scheme 2024 Punjab Board
  • 9th Class Pakistan Studies Guess Papers 2024 Punjab Board
  • 12th Class Biology Paper Pairing Scheme 2024 Punjab Board
  • Physics 12th Class Paper Scheme 2024 Punjab Board
Fsc Online | Online Notes, Educational News & Latest Government Job Updates
  • Home
  • Notes
    • Online Courses
      • 12th Class
      • 11th Class
      • 10th Class
      • 9th Class
  • Jobs
    • PPSC Jobs
    • SPSC Jobs
    • Punjab Police Jobs
  • Education News
  • E-Books
    • Punjab Text Book (PTB)
  • Model Papers
  • Results
  • Admissions
  • Colleges
  • More
    • Paper Schemes
    • Date Sheets
    • Guess Papers
    • Roll No Slips
Fsc Online | Online Notes, Educational News & Latest Government Job UpdatesFsc Online | Online Notes, Educational News & Latest Government Job Updates
Home » Computer Science » C Language » C Programs » [C/C++] Program to Find Factorial Using All Loops
C Language

[C/C++] Program to Find Factorial Using All Loops

October 2, 2015Updated:September 13, 2018No Comments2 Mins Read
WhatsApp Facebook Twitter Pinterest LinkedIn Tumblr Email

A simple c and c++ program to find factorial of given number.
Factorial of a number is product of all previous number from 1 to that number and it’s denoted by n! .
Example if you want to find the product of 5 it’ll be factorial= 5*4*3*2*1.
General Term: factorial = n*(n-1)*(n-2)*(n-3)…..3*2*1.

Below is the code to find factorial. I’ve used all loops one by one to find factorial of given number just as an example to show you how it’ll be vary from loop to loop.

C Code

#include<stdio.h>
#include<conio.h>

int main()
{
 int num, for_factorial=1, do_factorial=1, while_factorial=1, i;

 printf("Enter Number To Find Its Factorial: ");
 scanf("%d", &num);

 //Using For Loop to Find Factorial
 for(i=1;i<=num;i++)
 {
 for_factorial=for_factorial*i;
 }

 //Using do While Loop to Find Factorial
 i=1;
 do
 {
 do_factorial=do_factorial*i;
 i++;
 }
 while(i<=num);
 
 //Using While Loop to Find Factorial
 i=1;
 while(i<=num)
 {
 while_factorial=while_factorial*i;
 i++;
 }
 
 printf("\nFactorial Using For Loop: %d", for_factorial);
 printf("\nFactorial Using While Loop: %d", while_factorial);
 printf("\nFactorial Using Do While Loop: %d", do_factorial);

 getch();
}

C++ Code

#include<iostream>

using namespace std;

int main()
{
 int num, for_factorial=1, do_factorial=1, while_factorial=1, i;

 cout << "Enter Number To Find Its Factorial: ";
 cin>>num;

 //Using For Loop to Find Factorial
 for(i=1;i<=num;i++)
 {
 for_factorial=for_factorial*i;
 }

 //Using do While Loop to Find Factorial
 i=1;
 do
 {
 do_factorial=do_factorial*i;
 i++;
 }
 while(i<=num);
 
 //Using While Loop to Find Factorial
 i=1;
 while(i<=num)
 {
 while_factorial=while_factorial*i;
 i++;
 }
 
 cout << "Factorial Using For Loop: " << for_factorial << endl;
 cout << "Factorial Using While Loop: " << while_factorial << endl;
 cout << "Factorial Using Do While Loop: " << do_factorial << endl;

 return 0;

}

Output:

Other Related Search Terms

  1. C++ program to find factorial using while, do while and for loop
  2. C program to find factorial using while, do while and for loop
  3. C++ find factorial of a given number
c programs computer science 2nd year cpp programs Online Course
Share. WhatsApp Facebook Twitter Pinterest LinkedIn Tumblr Email
Khurram Farooq
  • Website
  • Facebook
  • Twitter

I'm a full-stack developer, specializing in the PHP, JS, Wordpress, MEAN Stack, MERN Stack & Django. I hold a high standard of quality in everything that I do.

Related Posts

How to do Exponents in Java – 3 Different Methods

January 12, 2020

Different Types of Processors And Their Features

January 12, 2020

Biology 1st Year Guess Paper 2018 Punjab Board

May 28, 2018

Leave A Reply Cancel Reply

RECENT POSTS

NADRA Islamabad Announced Latest April Jobs 2024

April 4, 2024

TEVTA Sargodha Announced Instructor / Clerk Jobs 2024

April 4, 2024

BPSC Announced Latest Jobs Through Advertisement no. 03/2024

April 4, 2024

All Subjects 12th Class Paper Scheme 2024 | Punjab Board

April 4, 2024
TRENDING THIS WEEK

Cambridge CAIE Announced Revised A-Level Exam Schedule 2023

May 23, 2023

Top 7 CSS Academies in Pakistan | List Of Best CSS Academies

October 23, 2019

BISE Lahore Board HSSC-II (12th Class) Result Gazette 2022

October 20, 2022
ABOUT US

Notes, Guess Papers, Old Papers, Jobs, Admissions, Results, Datasheets and everything else that falls into the wide world of education & careers. For any assist and query please contact us.

Home · About Us · Team · Contact · Advertise · DMCA Policy · Cookies Policy · Privacy Policy
© 2013-2025 Powered By FScOnline - Made with ♥ for the students of Pakistan.

Type above and press Enter to search. Press Esc to cancel.

Exit mobile version
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkPrivacy policy