Loading....
Coupon Accepted Successfully!

 

Question-1

Define statement.

Solution:
Statements are the instructions given to the computer to perform any kind of action, be it data movements, and be it making decisions or be it repeating actions. Statements are smallest executable unit within a C++ program. Statements are terminated with a semicolon (;).

Question-2

Explain sequence construct.

Solution:
The sequence construct means the statement are being sequentially. This represents the default flow of statement. Each statement in turn is executed. When the final statement main() is executed the program is done.

Question-3

What is iteration?

Solution:
This statement causes statements to be executed zero or more times which subject to some loop termination. They may be compound statements. If they are compound statements then they execute the statement in an order but terminate when the break statement is found. Some of the iteration statements are while, do and for.

Question-4

Explain If statement in detail.

Solution:
This statement is used to execute or skip one statement or group of statements for particular conditions. The general format is given in the following table.

 

if(test condition)

{

Statement block;

}

next statement;

 

When this statement is executed, the computer first evaluates the value of the test condition.

It the value is true the statement block and next statement are executed.

If the value is false, statement block is skipped and execution starts from next statement.

Question-5

Write a program to accept three integer values and print the largest.

Solution:
#include<iostream.h>

main()

{

int x,y,z,max;

cout<< " enter the value";

cin >>x>>y>>z;

max = x;

if ( y> max)

max = y;

if (z > max)

max = z;

cout <<"the largest of "<<x<<y<<z <<"is" << max;

}

Question-6

Give the syntax for nested if statement.

Solution:
if (expression 1)

{

if (expression 2)

statement 1;

else

statement 2;

}

else

statement 3;

}

Question-7

Give the syntax for switch case statement.

Solution:
switch (expression)

{

case label1:

   statement1;

   break;

case label2:

   statement1;

   break;

case label3:

   statement1;

   break;

default:

   default statement;

   break;

}

   next statement;

Question-8

Write the different between " =" and "==" symbol.

Solution:
In this equal to (=) symbol is used for assigning.

Where as double equal to (==) is used for checking equality.

Question-9

Write a program to check whether the given number is a palindrome or not.

Solution:
#include<iostream.h>

main()

{

Int n, num, digit, rev = 0;

Cout<<" input the number ";

cin >> num;

n = num;

do

{

digit =num %10;

rev = (rev * 10) + digit;

num = num / 10;

}while (num!=0);

Cout<<rev;

If(n ==rev)

cout << "it is a palindrome";

else

cout << "it is not a palindrome";

}

}

Question-10

Write a program to demonstrate switch case statement.

Solution:

#include<iostream.h>

void main()

{

int day;

cout<< "enter the number between 1 and 7";

cin>> day;

switch(day)

{

case 1:

cout "Monday";

break;

case 2:

cout "Tuesday";

break;

case 3:

cout "Wednesday";

break;

case 4:

cout "Thursday";;

break;

case 5:

cout "Friday";

break;

case 6:

cout "Saturday";

break;

case 7:

cout "Sunday";

break;

default:

cout<< " enter the correct number’;

break;

}

}

Question-11

Give the syntax for ‘for loop’.

Solution:
The syntax for ‘for loop’ is

for (initialization, test condition, iteration)

{

body of the loop;

}

next statement;

 

Question-12

Write a program to illustrate while statement.

Solution:

#include <iostream.h>

void main()

{

int i;

i =1;

while( i < 5)

{

cout <"god loves you’;

i++;

}

}

Question-13

Give the flow chart representation of do…. While loop.

Solution:

Question-14

Write a program to illustrate the usage of break statement.

Solution:

#include <iostream.h>

void main()

{

int i;

for (i = 1; i < 10; i++)

{

cout<<"\n"<< i;

if (i == 4)

break;

}

}

Question-15

Write a program to show the working of continue statement.

Solution:
#include <iostream.h>

main()

{

int i = 0;

do

{

i++;

cout<<"before the continue\n";

continue;

cout<<"after the continue, should never print\n";

}

while (i < 3);

cout<<"after the do loop\n";

}





Test Your Skills Now!
Take a Quiz now
Reviewer Name