Q:
C++ goto Statement | Find output programs | Set 1
belongs to collection: C++ find output programs
C++ find output programs
- C++ Operators | Find output programs | Set 1
- C++ Operators | Find output programs | Set 2
- C++ const Keyword | Find output programs | Set 1
- C++ const Keyword | Find output programs | Set 2
- C++ Manipulators | Find output programs | Set 1
- C++ Manipulators | Find output programs | Set 2
- C++ Reference Variable | Find output programs | Set 1
- C++ Reference Variable | Find output programs | Set 2
- C++ Conditional Statements | Find output programs | Set 1
- C++ Conditional Statements | Find output programs | Set 2
- C++ Switch Statements | Find output programs | Set 1
- C++ Switch Statements | Find output programs | Set 2
- C++ goto Statement | Find output programs | Set 1
- C++ goto Statement | Find output programs | Set 2
- C++ goto Statement | Find output programs | Set 2
- C++ Looping | Find output programs | Set 1
- C++ Looping | Find output programs | Set 2
- C++ Looping | Find output programs | Set 3
- C++ Looping | Find output programs | Set 4
- C++ Looping | Find output programs | Set 5
- C++ Default Argument | Find output programs | Set 1
- C++ Default Argument | Find output programs | Set 2
- C++ Arrays | Find output programs | Set 1
- C++ Arrays | Find output programs | Set 2
- C++ Arrays | Find output programs | Set 3
- C++ Arrays | Find output programs | Set 4
- C++ Arrays | Find output programs | Set 5
- C++ Strings | Find output programs | Set 1
- C++ Strings | Find output programs | Set 2
- C++ Strings | Find output programs | Set 3
- C++ Strings | Find output programs | Set 4
- C++ Strings | Find output programs | Set 5
- C++ Class and Objects | Find output programs | Set 1
- C++ Class and Objects | Find output programs | Set 2
- C++ Class and Objects | Find output programs | Set 3
- C++ Class and Objects | Find output programs | Set 4
- C++ Class and Objects | Find output programs | Set 5
- C++ Constructor and Destructor | Find output programs | Set 1
- C++ Constructor and Destructor | Find output programs | Set 2
- C++ Constructor and Destructor | Find output programs | Set 3
- C++ Constructor and Destructor | Find output programs | Set 4
- C++ Constructor and Destructor | Find output programs | Set 5
- C++ this Pointer | Find output programs | Set 1
- C++ this Pointer | Find output programs | Set 2
- C++ this Pointer | Find output programs | Set 3
- C++ Structures | Find output programs | Set 1
- C++ Structures | Find output programs | Set 2
- C++ Structures | Find output programs | Set 3
- C++ Structures | Find output programs | Set 4
- C++ Structures | Find output programs | Set 5
- C++ Friend Function | Find output programs | Set 1
- C++ Friend Function | Find output programs | Set 2
- C++ Function Overloading | Find output programs | Set 1
- C++ Function Overloading | Find output programs | Set 2
- C++ Function Overloading | Find output programs | Set 2
- C++ Function Overloading | Find output programs | Set 3
- C++ Static Variables and Functions | Find output programs | Set 1
- C++ Static Variables and Functions | Find output programs | Set 2
- C++ Static Variables and Functions | Find output programs | Set 3
- C++ Static Variables and Functions | Find output programs | Set 4
- C++ Static Variables and Functions | Find output programs | Set 5
- C++ Operator Overloading | Find output programs | Set 1
- C++ Operator Overloading | Find output programs | Set 2
- C++ Operator Overloading | Find output programs | Set 3
- C++ Operator Overloading | Find output programs | Set 4
- C++ Operator Overloading | Find output programs | Set 5
- C++ Enumeration | Find output programs
- C++ Inheritance | Find output programs | Set 1
- C++ Inheritance | Find output programs | Set 2
- C++ Inheritance | Find output programs | Set 3
- C++ Inheritance | Find output programs | Set 4
- C++ Inheritance | Find output programs | Set 5
- C++ Exceptional Handling | Find output programs | Set 1
- C++ Exceptional Handling | Find output programs | Set 2
- C++ Exceptional Handling | Find output programs | Set 3
- C++ Virtual Functions | Find output programs | Set 1
- C++ Virtual Functions | Find output programs | Set 2
- C++ Virtual Functions | Find output programs | Set 3
- C++ Templates | Find output programs | Set 1
- C++ Templates | Find output programs | Set 2
- C++ Preprocessor | Find output programs | Set 1
- C++ Preprocessor | Find output programs | Set 2
- C++ Preprocessor | Find output programs | Set 3
- C++ Signal Handling | Find output programs | Set 1
- C++ Namespace | Find output programs | Set 1
- C++ Namespace | Find output programs | Set 2
- C++ Dynamic Memory Allocation | Find output programs | Set 1
- C++ Dynamic Memory Allocation | Find output programs | Set 2
- C++ Dynamic Memory Allocation | Find output programs | Set 3
Answer Program 1:
Output:
Explanation:
The above code will print "1 4 9 16 25" on the console screen.
Understand the program step by step.
Here we initialize the variables num1 and num2 by 1, 0 respectively. And we created a label MY_LABEL.
Now evaluate statements iteration wise:
First iteration:
num1=1, num2=0 num2 = num1 * num1; Then num1 = 1 and num2 = 1 and then print num2 that is 1. As we know that if we calculate the zero power of any number that will be 1. num1 = num1 + pow(2,0); Then the above statement will increase the value of num1 by one. Then num1 become 2. And num1 is less than equal to 5 then "goto" statement will transfer the program control to the MY_LABEL.
Second iteration:
num1=2, num2=0 num2 = num1 * num1; After execution of above statement, num1=2 and num2=4 and then print num2 that is 4 num1 = num1 + pow(2,0); Then above statement will increase the value of num1 by one. Then num1 become 3. And num1 is less then equal to 5 then "goto” statement will transfer the program control to the MY_LABEL.
Third Generation:
num1=3, num2=0 num2 = num1 * num1; After execution of above statement, num1=3 and num2=9 and then print num2 that is 9 num1 = num1 + pow(2,0); Then above statement will increase the value of num1 by one. Then num1 become 4. And num1 is less then equal to 5 then "goto" statement will transfer the program control to the MY_LABEL.
Fourth iteration:
num1=3, num2=0 num2 = num1 * num1; After execution of above statement, num1=4 and num2=16 and then print num2 that is 16 num1 = num1 + pow(2,0); Then above statement will increase the value of num1 by one. Then num1 become 5. And num1 is less then equal to 5 then "goto" statement will transfer the program control to the MY_LABEL.
Fifth iteration:
num1=3, num2=0 num2 = num1 * num1; After execution of above statement, num1=5 and num2=25 and then print num2 that is 25 num1 = num1 + pow(2,0); Then above statement will increase the value of num1 by one. Then num1 become 6. Then condition get false and program get terminated.
Answer Program 2:
Output:
Explanation:
The above code will print "1 2 4 7" on the console screen.
Understand the program step by step.
Here we initialize the variables num1, num2, and num3 by 1, 0, and 1 respectively. And we created a label MY_LABEL.
Now evaluate statements iteration wise:
First iteration:
Here initial values of num1=1, num2 =0, and num3 =1 after executing all statements "1" will be printed on console screen and modified value will be: num1 = 2, num2 = 1, num3= 1; If the condition is true then program control will be transferred to MY_LABEL.
Second iteration:
Here values of num1=2, num2 =1, and num3 =1 after executing all statements "2" will be printed on console screen and modified value will be: num1 = 3, num2 = 2, num3= 2; If the condition is true then program control will be transferred to MY_LABEL.
Third iteration:
Here values of num1=3, num2 =2, and num3 =2 after executing all statements "4" will be printed on console screen and modified value will be: num1 = 4, num2 = 3, num3= 4; If the condition is true then program control will be transferred to MY_LABEL.
Fourth iteration:
Here values of num1=4, num2 =3, and num3 =4 after executing all statements "7” will be printed on console screen and modified value will be: num1 = 4, num2 = 4, num3= 7; Now the if condition gets false and the program will terminate.
need an explanation for this answer? contact us directly to get an explanation for this answer