adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in c++ to print 1 to nth numbers of factorial



Using single for loop


//clanguage0.blogspot.com
#include<iostream>
#include<conio.h>
 using namespace std;
 int main()
 {
    int i,n,f;
    cout<<" Enter a number:-";
    cin>>n;
    for(f=1,i=1;i<=n;i++)
    {
        f=f*i;
        cout<<" Factorial "<<i<<" = "<<f<<endl;
    }
  getch();
 }
Output:-








Using double for loop

//clanguage0.blogspot.com
#include<iostream>
#include<conio.h>
 using namespace std;
 int main()
 {
    int i,n,f,n1;
    cout<<" Enter a number:-";
    cin>>n1;
    for(n=1;n<=n1;n++)
    {
     for(f=1,i=1;i<=n;i++)
      {
        f=f*i;
      }
      cout<<" Factorial "<<n<<" = "<<f<<endl;
    }
  getch();
 }
Output:-


Post a Comment

0 Comments