1. Program to display number in incrementing and decrementing order using while loop.

Chapter 6: 

Looping Structures

Programming Exercise

Problem # 1:

Write a program to display the following format using while loop:
    ---------
    a        b
    ---------
    1        5
    2        4
    3        3
    4        2
    5        1
    ---------

Solution:

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    int i=1, j=5;
    cout<<"a\tb"<<endl;
    while(i<=5&&j>=1)
    {
        cout<<i<<"\t"<<j<<endl;
        i++;
        j--;
    }
    return 0;
}


Let me know in the comment section if you have any question.

Previous Post:
17. Program that inputs a value and type of conversion. The program should then displays the output after conversion.

Comments