C++ program to print output like below using loops 1 2==1 3==2==1 4==3==2==1 5==4==3==2==1 6==5==4==3==2==1 7==6==5==4==3==2==1 8==7==6==5==4==3==2==1 9==8==7==6==5==4==3==2==1 (with algorithm)

C++ program to print output like below using loops
1
2==1
3==2==1
4==3==2==1
5==4==3==2==1
6==5==4==3==2==1
7==6==5==4==3==2==1
8==7==6==5==4==3==2==1
9==8==7==6==5==4==3==2==1

Here is the C++ code to output like above . You all should have in mind how it works exactly. Here is the algorithm.

  Steps
User side
1: When user run this code it simply output the result 
Developer side
1: Declare variables that are going to be used in program .
2: Start a loop from i=1 to 9 
3:  Inside the above loop initialize a variable equal to above one a=i and iterate it until the following statement fails a>=1
4: Inside the above loop output "a" and output "==" if a!=1 (a is not equal to one)
5: outside the above loop output a next line using cout<<endl;
6: Program ends here


SO here is the C++ code.

Code:

//start
#include<iostream>
using namespace std;

void main()
{      int i=1,a,b;
       while(i<=9)
              {      a=i;
                     while(a>=1)
                           {      cout<<a;
                                  if(a!=1)
                                  {
                                         cout<<"==";
                                  }

                                  a--;
                           }
                     cout<<endl;
                     i++;
              }
       system("pause");
}

//End



Output:


Comments