10 June , 2019.
“ LAB NO # 8 “
TASK NO :- 1 Write a program in C++ that take display your name five times,
using do while loop .
PROGRAM :-
#include<iostream>
using namespace std;
int main ()
int a;
cout <<" enter a value of a = ";
do
{ cout << "MY NAME IS JUNAID ALI " << endl;
a++;
while ( a<6);
OUTPUT :-
TASK NO # 2 :- Write a program in C++ that take multiple integer types values from the user and
calculate the sum after entering 0. The code should terminate at 0.
PROGRAM :-
#include<iostream>
using namespace std;
int main ()
int a,result = 0;
cout << " Enter a integer value ";
while ((cin >> a)&& (a != 0))
cout << a;
result += a;
cout << "SUM OF ALL INTEGERS ARE " << result ;
OUTPUT :-
Task # 3 :- Convert the following while loop to do-while loop and show the output
after execution.
int x = 1 ;
while ( x > 0 )
{ cout<< “ Enter a number “
cin >> x;
CODE :-
#include<iostream>
using namespace std;
int main ()
int a = 1 ;
do {
cout << " Enter a NUMBER ";
cin >> a;
while (a>0);
OUTPUT :-
Task # 4 :- Convert the following do-while loop to while loop and show the
output after execution.
char sure ;
do
{ cout << :” Are you sure you want to quit ? “
cin >> sure ;
while (sure! = ’Y’ && sure!= ’N’ ) ;
PROGRAM :-
#include<iostream>
using namespace std ;
int main ()
char sure;
cout << " Are you sure you want to quit ??";
cin >> sure ;
while ((sure != 'n')&&(sure != 'y'))
cout << " Again enter a Character please ";
cin >> sure ;
cout << endl; } }
OUTPUT :-
TASK NO # 6 :- Convert the following while loop to for loop and show the output after
execution.
int count =0 ;
while (count < 50)
{ cout<< “COUNT IS = “ << count << endl ;
count++;
PROGRAM :-
#include<iostream>
using namespace std;
int main ()
{ int count = 0 ;
do
cout << " The COUNT is = " << count << endl ;
count ++;
while (count < 50);
OUTPUT :-
COMMENTS :-
We have learned a lot after performing this lab and a lot of ambiguous points became
cleared after the lecture of the instructor. We can now easily perform any of the task given to us
regarding this topic.