Here is the solution if you have any doubts then you can write in the comment section.
Please give feedback.
Solution:
(1)
static int num;
if we don't assign value to static then by default its value become
0;
Now we consider for loop:
for loop contains 4 steps in execution:
for(initialization;condition check;updation)
{
statement execution;
}
Step 1: initialization step execute.
Step 2: condition check, if condition true then repeat step 3 and 4
Step 3: statement execution
Step 4:updation(increment / decrement)
So we will find our output by using above 4 steps:
for(num++;++num;num++)
{
printf("%d",num);
if(num==8)
break;
}
step1: num++ now num=1
step2: ++num now num=2 it is true so we will repeat step 3 and 4
step3:
printf("%d",num); it will print 2
num != 8 so continue with loop
step 4: updation num++ now num=3
step 5: condition check ++num now num=4
step6:
printf("%d",num); it will print 4
num != 8 so continue with loop
step 7: updation num++ now num=5
step 8: condition check ++num now num=6
step9:
printf("%d",num); it will print 6
num != 8 so continue with loop
step 10: updation num++ now num=7
step 11: condition check ++num now num=8
step12:
printf("%d",num); it will print 8
here num==8 so break from loop
So final output will be:- 2 4 6 8
(2)
line 1: int test;
line 2: for(test=0;test<=5;test++);
line 3: printf("%d",test);
In line 1 a variable test is declared;
In line 2 a for loop is present; but loop is ended with a semicolon ( ; )
it means step 3 is missing according to our rules which I define above.
so for loop execution:
step 1: test=0;
step2: test<=5 true so repeat step 4 until it is true (step3 is not present according to our rules)
step3: nothing
step4: updation test++; so test=1;
step 5: test<=5 true so repeat
step 6: updation test++; so test=2;
step 7: test<=5 true so repeat
step 8: updation test++; so test=3;
step 9: test<=5 true so repeat
step 10: updation test++; so test=4;
step 11: test<=5 true so repeat
step 12: updation test++; so test=5;
step 13: test<=5 true so repeat
step 14: updation test++; so test=6;
step 15: test<=5 which is false now so break from for loop with test=6;
So now we will reach to line 3: printf("%d",test); so it will print 6
So final Output: 6
Thank You!
please help me asap 1 Determine the output for the following code: #include<stdio.h> int main static...
22. (6 points) Determine the output for the following coe # include < stdio.h > int main(void) ( int z 1, total -0, y printf(d , x) ) //end-for printf("The total %d\n", total) ) //end-main
QUESTIONS What will be the output of the following C code? 1. #include <stdio.h> int maino int 1 - -3; int k - * % 2; printf(\n", k); Compile time error O-1 Implementation defined
Convert the below code into if else selection: #include <iostream> using namespace std; int main() { int num; sin. >> num; switch (num) { case 1: cout << "Casel: Value is: << num << endl; break; case 2: break; case 3: cout << "Case3: Value is: " << num << endl; break; default: cout << "Default: Value is: << num << endl; break; } return; }
What is printed when the following code is executed? #include <stdio.h> int main() { for (int i=3, j=5; i>=0; i-=2, j+=j*i) { printf("%d", j); منم }
Question 3 Predict the output of the following C program: #include <stdio.h> void main() { int i = 0; for(; 1; i++){ printf("%d",i); if(i==7) break; } 12pt Paragraph 1 Β Ι Ο Αν και Ta
1. What is the output of the following program? include <stdio.h> int wilma (int x) if (x<5) x = 7; return (x) int main (void) int x-1 x=wilma (x) ; printf ("%d", x); return (0) b)3 c) 4 d) 7 a) 1 e) none of these
6. Consider the following program: #include <stdio.h> main() { int a,b,c,d ; a=0; while (1) { printf("%d\n", a); printf("Input? "); scanf("%d",&c); if (c == 0) break; d=0; for (b=1; b<=c; b++) if (c%b == 0) d++; if (d == 2 11 C == 1) a=a+c; } } What does this program do? Rewrite the code, organizing it using sound principles. Include comments and redo variable names and indentation. Use multiple functions, blocks, and/or preprocessing if you deem it necessary.
Q4) what is the output after the code below is executed? #include <stdio.h> #1 nclude<string.h> int main) char abc[100]-"Good Luck in Your Programming Final" int i, ; while(abc[i]!= '\0'){ if(abc[i]' if(abc[i+1]-'&&abci+1] -'0' else printf"c", abcli-1]) printf("\n w = %d return 0; \n", w); Place you answer here 4 l Page
QUESTION 12 What is the output of the following program? #include <stdio.h> int main(void) printf("From sealnto shininginC"); O a. From sea to shining O b. From sea to shining O c. From seanto shining nC O d. From sea to shining C
MIPS assembly language Covert this code to MIPS: #include <stdio.h> int function (int a) int main)i int x=5 ; int y: y function(x); printf "yd",y); return 0; int function (int a) return 3*a+5; Assumptions: . Place arguments in $a0-$a3 . Place return values in $vO-$v1 Return address saved automatically in $ra . lgnore the stack for this example. (Thus, the function will destroy registers used by calling function