Question #24722

...plz tell me which of the output or outputs will be displayed in each one...AND ALSO MENTION HOW CAN U FIND THE OUTPUT RELATED TO SUCH QUESTION ~

1)

#include<iostream.h>

#include<stdlib.h>

const int limit = 4;

void main()

{

randomize();

int points;

points = 100 + random(limit);

for(int p = points ; p>= 0 ;p--)

cout<<p<<"\t";

cout<<endl;

}

possible outputs ----

a)103 102 101 100

b)100 101 102 103

c)100 101 102 103 104

d)104 103 102 101 100

1)

#include<iostream.h>

#include<stdlib.h>

const int limit = 4;

void main()

{

randomize();

int points;

points = 100 + random(limit);

for(int p = points ; p>= 0 ;p--)

cout<<p<<"\t";

cout<<endl;

}

possible outputs ----

a)103 102 101 100

b)100 101 102 103

c)100 101 102 103 104

d)104 103 102 101 100

Expert's answer

The command

const int limit =4;

on line 3 sets limit to 4

Then the command

points = 100 +random(limit);

on line 8 sets variable "points" to a number

100 + someinteger number from the interval [0,4), where 4 is not included.

Thus the variable "points" takes one of values:100,101,102,103.Further in the loop

for(int p =points ; p>= 0 ;p--)

in the line 9 the variable "p" will be decreasefrom points to 0 with step 1.

The body of the loop consists of a unique line 10:

cout<<p<<" ";

which prints p.

Hence the reare only 4 possible outputs of the program:

100 99 98 ... 0

101 100 99 98... 0

102 101 100 99 98 ... 0

103 102 101 100 99 98 ... 0

Hence possible output is only a):

a)103 102 101100

Since in

b)100 101 102103

c)100 101 102103 104

the numbers increase,

and in

d)104 103 102101 100

the sequence starts from 104

Thus the answer is a)

const int limit =4;

on line 3 sets limit to 4

Then the command

points = 100 +random(limit);

on line 8 sets variable "points" to a number

100 + someinteger number from the interval [0,4), where 4 is not included.

Thus the variable "points" takes one of values:100,101,102,103.Further in the loop

for(int p =points ; p>= 0 ;p--)

in the line 9 the variable "p" will be decreasefrom points to 0 with step 1.

The body of the loop consists of a unique line 10:

cout<<p<<" ";

which prints p.

Hence the reare only 4 possible outputs of the program:

100 99 98 ... 0

101 100 99 98... 0

102 101 100 99 98 ... 0

103 102 101 100 99 98 ... 0

Hence possible output is only a):

a)103 102 101100

Since in

b)100 101 102103

c)100 101 102103 104

the numbers increase,

and in

d)104 103 102101 100

the sequence starts from 104

Thus the answer is a)

Learn more about our help with Assignments: C++

## Comments

## Leave a comment