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:-
0 Comments