# Programming Exercise Looping Structure P-5

Programming Exercise Looping Structure P-4

IF Statement Programming Exercise Part-1

#### Q.1 Write a program that displays the following output using the while loop:// 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,……………………, 98, 99, 100

```#include<iostream.h>
#include<conio.h>
main()
{
int n;
n = 1;
clrscr();
while(n <= 100)
{
cout<<n<<'\t';
n++;
}
getch();
}```

#### Q.2 Write a program that displays the following output using the while loop:// 1, 4, 7, 10, 13, 16, 19, 22, 25,2 8,………………… , 82, 85, 88, 91, 94, 97, 100

```#include<iostream.h>
#include<conio.h>
main()
{
int n;
n = 1;
clrscr();
while(n <= 100)
{
cout<<n<<'\t';
n=n+3;
}
getch();
}```

#### Q.3 Write a program that displays the following output using the while loop://1, 5, 9, 13, 17, 21, 25, 29, 33,………………….,73, 77, 81, 85, 89, 93, 97, 101

```#include<iostream.h>
#include<conio.h>
main()
{
int n;
n = 1;
clrscr();
while(n <= 101)
{
cout<<n<<'\t';
n=n+4;
}
getch();
}```

#### Q.4 Write a program that displays the following output using the while loop:// 1, 6, 11, 16, 21, 26, 31, 36, 41,………………,71, 76, 81, 86, 91, 96, 101

```#include<iostream.h>
#include<conio.h>
main()
{
int n;
n = 1;
clrscr();
while(n <= 101)
{
cout<<n<<'\t';
n=n+5;
}
getch();
}```

#### Q.5 Write a program that displays the following output using the while loop:// 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20……………………, 98, 100

```#include<iostream.h>
#include<conio.h>
main()
{
int n;
n = 0;
clrscr();
while(n <= 100)
{
cout<<n<<'\t';
n=n+2;
}
getch();
}```

#### Q.6 Write a program that displays the following output using the while loop:// -10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10

```#include<iostream.h>
#include<conio.h>
main()
{
int n;
n = -10;
clrscr();
while(n <= 10)
{
cout<<n<<'\t';
n=n+2;
}
getch();
}```

#### Q.7 Write a program that displays the following output using the while loop:// 101, 99, 97, 95, 93, 91, 89,……………….…,13, 11, 9, 7, 5, 3, 1

```#include<iostream.h>
#include<conio.h>
main()
{
int n;
n = 101;
clrscr();
while(n >= 1)
{
cout<<n<<'\t';
n=n-2;
}
getch();
}```

#### Q.8 Write a program that displays the following output using the while loop:// 100, 97, 94, 91, 88, 85,………………….…,22, 19, 16, 13, 10, 7, 4, 1

```#include<iostream.h>
#include<conio.h>
main()
{
int n;
n = 100;
clrscr();
while(n >= 1)
{
cout<<n<<'\t';
n=n-3;
}
getch();
}```

#### Q.9 Write a program that displays the following output using the while loop:// 101, 97, 93, 89, 85,………………….…,33, 29, 25, 21, 17, 13, 9, 5, 1

```#include<iostream.h>
#include<conio.h>
main()
{
int n;
n = 101;
clrscr();
while(n >= 1)
{
cout<<n<<'\t';
n=n-4;
}
getch();
}```

#### Q.10 Write a program that displays the following output using the while loop:// 101, 96, 91, 86, 81,……………….…,36, 31, 26, 21, 16, 11, 6, 1

```#include<iostream.h>
#include<conio.h>
main()
{
int n;
n = 101;
clrscr();
while(n >= 1)
{
cout<<n<<'\t';
n=n-5;
}
getch();
}```

#### Q.11 Write a program that displays the following output using the while loop:// 103, 97, 91, 85, 79, 73,………………,49, 43, 37, 31, 25, 19, 13, 7, 1

```#include<iostream.h>
#include<conio.h>
main()
{
int n;
n = 103;
clrscr();
while(n >= 1)
{
cout<<n<<'\t';
n=n-6;
}
getch();
}```

#### Q.12 Write a program that displays the following output using the while loop:// 100, 98, 96, 94, 92, 90, 88, 86, 84, 82, 80,……………,10, 8, 6, 4, 2, 0

```#include<iostream.h>
#include<conio.h>
main()
{
int n;
n = 100;
clrscr();
while(n >= 0)
{
cout<<n<<'\t';
n=n-2;
}
getch();
}```

#### Q.13 Write a program that displays the following output using the while loop:// 12, 10, 8, 6, 4, 2, 0, -2, -4, -6, -8, -10, -12

```#include<iostream.h>
#include<conio.h>
main()
{
int n;
n = 12;
clrscr();
while(n >= -12)
{
cout<<n<<'\t';
n=n-2;
}
getch();
}```

#### Q.14 Write a program that displays the following output using the while loop:// 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10

```#include<iostream.h>
#include<conio.h>
main()
{
int n;
n = 10;
clrscr();
while(n >= -10)
{
cout<<n<<'\t';
n--;
}
getch();
}```

#### Q.15 Write a program that displays the following output using the while loop:// 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024.

```#include<iostream.h>
#include<conio.h>

main()
{
int n;
n = 1;
clrscr();
while(n <= 1024)
{
cout<<n<<'\t';
n = n*2;
}
getch();
}```

#### Q.16 Write a program that generates the following series using the ‘while’ loop.// 64 32 16 8 4 2

```#include<iostream.h>
#include<conio.h>
main()
{
int n;
n = 64;
clrscr();
while(n>=2)
{
cout<<n<<'\t';
n = n/2;
}
getch();
}```

#### Q.17 Write a program that generates the following series using the ‘while’ loop statement:// 1, 3, 9, 27, 81,….

```#include<iostream.h>
#include<conio.h>
main()
{
int n;
n = 1;
clrscr();
while(n<=81)
{
cout<<n<<'\t';
n = n*3;
}
getch();
}```