3 What will the following program segment display int a0 whi

(3) What will the following program segment display?
int a=0;
while (a<100)
a+=10;
cout<<a;
(4) Use a preprocessor directive to define a named constant PI to be 3.1415926.
(3) What will the following program segment display?
int a=0;
while (a<100)
a+=10;
cout<<a;
(4) Use a preprocessor directive to define a named constant PI to be 3.1415926.

Solution

(3) What will the following program segment display?

int a=0; // this line declare a varable \'a\' of type int and initializing with 0
while (a<100) // iterate till a value is less than 100
a+=10; // adding 10 in a (a = a+10)

cout<<a; // displaying \'a\'

So, in while loop, each time we are adding 10 in \'a\'
first iteration: a = 0+10 = 10
second iteration: a = 10+10 = 20
third iteration: a = 20 + 10= 30
fourth iteration: a = 30 + 10= 40
fifth iteration: a = 40 + 10= 50
sixth iteration: a = 50 + 10= 60
seventh iteration: a = 60 + 10= 70
eighth iteration: a = 70 + 10= 80
ninth iteration: a = 80 + 10= 90
thenth iteration: a = 90 + 10= : While loop condition evaluates \'false\'

So finally value of a = 100
Output: 100

(4) Use a preprocessor directive to define a named constant PI to be 3.1415926.
#define PI 3.1415926

(3) What will the following program segment display? int a=0; while (a<100) a+=10; cout<<a; (4) Use a preprocessor directive to define a named constant

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site