Question

In: Computer Science

int value = 1; do { if (value % 2 == 0) cout << value <<...

int value = 1;

do

{

if (value % 2 == 0)

cout << value << " ";

value = value + 1;

}

while (value % 7 != 0);

cout << "\n" << value;

What will be displayed?

Solutions

Expert Solution

Answer

Here is your answer, if you have any doubt please comment. i am here to help you.


Remember:

do_ while(): always executes body at once ,if condition is true or false.

So here. You will get the following output

I will give you how this output come with detailed step.

here is the execution of your program.

value=1;  //initially

//check the body first iteration
1) i%2==0  here 1%2==0 which is FALSE, then value increment with 1, value=2.
2) check the condition for while loop, check (2%7!=0) which TRUE, then Inside loop, check (2%2==0) 
   which is TRUE, print the value of VALUE (2) then value=2+1=3.
3) check (3%7!=0) which is TRUE, then inside the loop, (3%2==0) which is FALSE, then VALUE=3+1=4
4) check (4%7!=0) which is TRUE, then inside the loop, (4%2==0) which is TRUE, then PRINT the 
   value of VALUE(4) then   VALUE=4+1=5
5) check (5%7!=0) which is TRUE, then inside the loop, (5%2==0) which is FALSE, then VALUE=5+1=6.
6) check (6%7!=0) which is TRUE, then inside the loop, (6%2==0) which is TRUE, then PRINT the 
   value of VALUE(6) then   VALUE=6+1=7.
7) check (7%7!=0) which is FALSE, loop will terminate.
8) print newline and print the current value of VALUE

any doubt please comment

Thanks in advance


Related Solutions

#include using namespace std; int menu(){    int x;    cout<<"1.Add Entry\n";    cout<<"2.Edit Entry\n";   ...
#include using namespace std; int menu(){    int x;    cout<<"1.Add Entry\n";    cout<<"2.Edit Entry\n";    cout<<"3.remove Entry\n";    cout<<"4.print Entry\n";    cout<<"5.Close Console\n";    cout<<"Enter Your Choice:-";    cin>>x;              return x; } int main() {    int x;    int entry[1000];    int entnum = 0;    int num = 0;    int nom =0;     while (1)     {         int choice = menu();         if (choice == 1){            cout<<"A entry " <<...
In Java: int[] A = new int[2]; A[0] = 0; A[1] = 2; f(A[0],A[A[0]]); void f(int...
In Java: int[] A = new int[2]; A[0] = 0; A[1] = 2; f(A[0],A[A[0]]); void f(int x, int y) { x = 1; y = 3; } For each of the following parameter-passing methods, saw what the final values in the array A would be, after the call to f. (There may be more than one correct answer.) a. By value. b. By reference. c. By value-result.
unsigned u =10; int i = -42; cout << i+i <<endl; cout << u+i<<endl;//if int take...
unsigned u =10; int i = -42; cout << i+i <<endl; cout << u+i<<endl;//if int take 32 bit, output 4294967264 I know when unsigned and singed operate together, they need to be converted, but why is the answer 4294967264? What does it have to do with int .…… 32 bit
int a = 3; int b = -2; if((a>0)&&(b>0)){ if (a>b) { System.out.println("A"); } else {...
int a = 3; int b = -2; if((a>0)&&(b>0)){ if (a>b) { System.out.println("A"); } else { System.out.println("B"); } } else if ((b<0)||(a<0)) { System.out.println("C"); } else { System.out.println("D"); }
#include <stdio.h> int main () { int value= 10; int value2= 5; value = value %2;...
#include <stdio.h> int main () { int value= 10; int value2= 5; value = value %2; printf("he FInal =value=%d\n", value); value +=3; printf("he FInal =value=%d\n", value); value ++; printf("he FInal =value=%d\n", value); value= ++value2; printf("he FInal =value=%d\n", value); value= value2--; printf("he FInal =value=%d\n", value); } what is output explain each print statement? exlain why?
int compare_and_swap(int *value, int expected, int new_value) { int temp = *value; if ( *value ==...
int compare_and_swap(int *value, int expected, int new_value) { int temp = *value; if ( *value == expected ) *value = new_value; return temp; } Suppose that a machine has an atomic compare_and_swap() instruction that sets the value to new_value only if the expression ( *value == expected ) is true. Regardless, compare_and_swap() always returns the original value of the variable value. Using the compare__and_swap() instruction, give a mutual-exclusion solution to the n-process critical section problem. Use only the shared variable...
What is the value of n after this code runs? 1 Point int n = 0;...
What is the value of n after this code runs? 1 Point int n = 0; int j = 7; if ((j!=0) && (n < 25)) { n = 1; if (j > 4) { n = 2; } else { n = 3; } } else { n = 4; if (j%2 >= 2) { n = 5; } else { n = 6; } }
static int product(int x,int y){ if(x==0||y==0){//checking if x or y is 0 return 0;//if x or...
static int product(int x,int y){ if(x==0||y==0){//checking if x or y is 0 return 0;//if x or y is 0, then the return value and x*y will be zero. }else if(y<0&&x<0){ x=-x;//Changing the sign of x y=-y;//Changing the sign of y }else if(x>=1){ return (y+product(x-1,y)); } return (x+product(x,y-1)); } find the space complexity and the time complexity of the above algorithm.
Translate c++ code into mips assembly: int main() {                 cout << "Numbers:" << endl;            &nbs
Translate c++ code into mips assembly: int main() {                 cout << "Numbers:" << endl;                                 int x[] = {18, 12, 6, 500, 54, 3, 2, 122};                 int i;                                 for (i=0; i<8; i++)                 {                                                 cout << x[i] << endl;                 }                 return 0; } below is my code: .data        str1: .ascii "Numbers:"     str2: .ascii "\n"    x: .word 18,12,6,500,54,3,2,122       .text                      ...
Show the output of the following code segment. int count=0;                         for (int i=2; i <=...
Show the output of the following code segment. int count=0;                         for (int i=2; i <= 4; i++ ) {                                     StdOut.println(i);                                     for (int j=1; j <3; j++) {                                                 count++;                                                 StdOut.println(i +" " + j +" "+ count);                                     }                         } count i j I print 0 2 1 3 1 1 1 2 3 2 2 3 3 3 3 4 3 Show the output of the function call statements shown.             double x =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT