You are on page 1of 6

NAME:WALEED IJAZ

ROLL N0:EE-1426
DISCIPLINE:EE
COURSE: F.O.P.

C++ NESTED PROGRAMS


NESTED DO WHILE LOOP
Program to make right angled triangle using ‘+’:
#include <iostream>
using namespace std;
int main()
{
int i=1,j;
do
{
j=1;
do
{
cout << "+";
j++;
}
while(j <= i);
i++;
cout << endl;
}
while(i <= 5);

return 0;
}

WALEED IJAZ 1
NESTED FOR LOOP
Program to make triangle using numbers :
#include <iostream>
using namespace std;
int main()
{
int rows;
cout << "Enter number of rows: ";
cin >> rows;
for(int i=rows; i>=1; i--)
{
for(int j=1; j<=i; j++)
{
cout << j << " ";
}
cout << endl;
}

return 0;
}

NESTED WHILE LOOP


Program to print ‘pass’ or ‘fail’:
#include<iostream>
using namespace std;
int main()
{
int a=1;
while(a<3)
{
cout<<"PASS"<<endl;
a++;
int b=0;
while(b<2)
{
cout<<"FAIL"<<endl;
b++;
}

WALEED IJAZ 2
}

return 0;
}

NESTED IF ELSE
Program to tell “stage of life” by age:
#include <iostream>
using namespace std;
int main()
{
int age;
cout<<"enter the age \n";
cin>>age;
if(age>=14)
{
if(age>=18)
{
cout<<"Adult \n";
}
else
{
cout<<"Teenager \n";
}
}
else
{
if (age >5 && age<14)
{
cout<<"Kid \n";
}
else
{
cout << "child \n";
}
}

return 0;
}

WALEED IJAZ 3
SWITCH PROGRAM
Program to tell vowels:
#include <iostream>
using namespace std;
int main()
{
char alphabet;
cout<<"Enter the Alphabet(In Capital Letter): ";
cin>>alphabet;

switch (alphabet)
{
case 'A': cout << “Your Character Is A. This alphabet is
Vowel\n";
break;

case 'E': cout << "Your Character Is E. This alphabet is


Vowel\n";
break;

case 'I': cout << "Your Character Is I. This alphabet is


Vowel\n";
break;

case 'O': cout << "Your Character Is O. This alphabet is


Vowel\n";
break;

case 'U': cout << "Your Character Is U. This alphabet is


Vowel\n";
break;

default: cout << "Your Character is Not Vowel. This alphabet is


consonant\n";
break;
}

return 0;
}

WALEED IJAZ 4
NESTED IF
Program to tell ‘passed’ or ‘failed’ in the exam:
#include <iostream>
using namespace std;
int main()
{
int mark = 100;

if (mark >= 50)


{
cout << "You are passed in the exam." << endl;
if (mark >= 90) {
cout <<"Excellent!" << endl;
}
else

cout << "You are failed in the exam." << endl;

return 0;
}

WALEED IJAZ 5
WALEED IJAZ 6

You might also like