Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
45 views7 pages

C++ Loop Conversion Lab Tasks

The document contains a lab assignment with 6 tasks involving writing C++ programs that use different types of loops. The tasks include: 1) Using a do-while loop to display a name 5 times, 2) Using a while loop to calculate the sum of integers entered until 0 is entered, 3) Converting a while loop to a do-while loop to display a number input, 4) Converting a do-while loop to a while loop to get a yes/no character input, 5) Converting a while loop to a for loop to count to 50, and 6) Comments on learning from completing the lab assignments.

Uploaded by

aslam gujjar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views7 pages

C++ Loop Conversion Lab Tasks

The document contains a lab assignment with 6 tasks involving writing C++ programs that use different types of loops. The tasks include: 1) Using a do-while loop to display a name 5 times, 2) Using a while loop to calculate the sum of integers entered until 0 is entered, 3) Converting a while loop to a do-while loop to display a number input, 4) Converting a do-while loop to a while loop to get a yes/no character input, 5) Converting a while loop to a for loop to count to 50, and 6) Comments on learning from completing the lab assignments.

Uploaded by

aslam gujjar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

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.

You might also like