Anda di halaman 1dari 6

QUESTIONS

1. Who is Written C++

2. State statements below and give an example


application in C++ Program.
a) Go to
#include <iostream>
using namespace std;
int main ()
{
// Local variable declaration:
int a = 10;
// do loop execution
LOOP:do
{
if( a == 15)

// skip the iteration.


a = a + 1;
goto LOOP;

}
cout << "value of a: " << a << endl;
a = a + 1;
}while( a < 20 );
return 0;

}
b)While

/* Example Program For While Loop In C++


little drops @ thiyagaraaj.com
Coded By:THIYAGARAAJ MP
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
// Variable Declaration
int a;
// Get Input Value
cout<<"Enter the Number :";
cin>>a;
int counter = 1;
//while Loop Block
while (counter <= a)
{

*/

cout<<"Execute While "<<counter<<"


time"<<endl;
counter++;
}

// Wait For Output Screen


getch();
return 0;

c) Break and Continue


#include <iostream>
int main()
{
int count(0); // count how many times the loop
iterates
bool exitLoop(false); // controls whether the loop
ends or not
while (!exitLoop)
{
std::cout << "Enter 'e' to exit this loop or any
other key to continue: ";
char ch;
std::cin >> ch;
if (ch == 'e')
exitLoop = true;
else
{
++count;
std::cout << "We've iterated " << count
<< " times\n";
}
}

return 0;

d)While True
#include <iostream>
using namespace std;
int main (int argc, char * const argv[]) {
int counter = 9;
while (true) {
cout << "Counter: " << counter << endl;;
counter--;
if (counter == 0) {
break;
}
}
return 0;
}
e) Do/ While

// do_while_statement.cpp
#include <stdio.h>
int main()
{
int i = 0;
do
{
printf_s("\n%d",i++);
} while (i < 3);

f) Jump / Loop

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout << "The loop with \'break\' produces
output as :\n" ;
for(int i = 1 ; i <= 10 ; i++)
{
if( (i%3) == 0 )
break ;
else
cout << i << endl ;
}
cout << "The loop with \'continue\' produce
output as : \n" ;
for(i = 1 ; i <= 10 ; i++)
{
if( (i%3) == 0 )
continue ;
else
cout << i << endl ;
}

g)If/ else
#include <iostream>
using namespace std;
int main ()
{
// local variable declaration:
int a = 100;
// check the boolean condition

if( a < 20 )
{
// if condition is true then print the following
cout << "a is less than 20;" << endl;
}
else
{
// if condition is false then print the following
cout << "a is not less than 20;" << endl;
}
cout << "value of a is : " << a << endl;
return 0;
}

Anda mungkin juga menyukai