What is the output of the following fragment?
please explain.
C language
int i = 1;
int j = 1;
while (i < 5) {
i++;
j = j * 2;
}
printf(“%d”, j);
(a) 4
(b) 8
(c) 16
(d) 32
int i = 1; int j = 1; while (i < 5) { i++; j = j * 2; } printf(“%d”, j); Let's trace through all iterations of while loop i = 1 i is increased to 2 j = j*2 = 1*2 = 2 i = 2 i is increased to 3 j = j*2 = 2*2 = 4 i = 3 i is increased to 4 j = j*2 = 4*2 = 8 i = 4 i is increased to 5 j = j*2 = 8*2 = 16 i = 5 loop exits because i < 5 is false. so, final value of j is 16 so, it prints 16 Answer: (c) 16
What is the output of the following fragment? please explain. C language int i = 1;...
20) What is the output of the following segment of C code: int avg(int n, int* a); int main () { int array[4]={1,0,6,9}; printf("%d", avg(4, array)+ 1); system("pause"); return 0; } int avg(int n, int* a) { int i, sum=0; for (i=0;i<n;i++) { sum+=a[i]; } return sum/n; } a) 16 b) 5 c) 4 d) 8 21) What is the output of the following segment of C code: int x = 2; int y = 3;...
What is the output of the following code fragment? int i = 1; while( i <= 5 ) if(i == 2 || i == 4) System.out.println(i + ":" + " is an even index) System.out.println("i: " + i); i++;
( C prog) write an output for the following code fragment int a[]= {1, 2, 3, 4, 5, 6}: int *ip; int i; ip=a; ip +=3; *ip= *ip * 3; for (i=0; i <6; ++i) printf("%d," a[i]);
Write the output from the following code fragment: for (int i = 1; I < 7; ++i) { switch (i) { case 1: printf ("\n%d Banana", i); case 2: printf ("\n%d Kumquat", i);
in C language please! 9. 14 points Show what the following C code will print. const int MAX_I_COUNT = 4; const int MAX_J_COUNT = 15; int i, j; for( i = 1; i <MAX_I_COUNT; i++) { for(j = 2; j <MAX_J_COUNT; j += 4 ) printf("%d", j + i); puts("\n-----" ); puts( "I'm Done!" ); 10. 14 points What would be printed? int bean = 5, cheese = 3; int *p = &bean; *p += bean; ++cheese; *p += cheese;...
PART A: Predict how many lines of output will be displayed by the following program fragment: i = 0 do { for (j = 0; j < 4; j = j + 1) printf("%d\n", i + j); i = i + 1; } while (i < 5); PART B: Then write either a C or a C++ program to verify your prediction. I know it will output 20 lines, the full C++ code is what I need.
should be in C language What is the output of the following segment of C code: void CapsLetter (char* x, charl); int main() { char* text; text="This is some sample text."; CapsLetter(text, 'e'); printf("%s", text); return 0; سی void Caps Letter (char* x, char 1) { int i=0; while (x[i]!='\0') { if (x[i]==1) x[i]=1-32; } 1. This is som sample text. 2. THIS IS SOME SAMPLE TEXT. 3. This is some sample text. 4. this is some sample text. What...
Given the following code in C, what is the output of this program? (10 Points) int mainO f 5. int i=10; for(int j-l;j-3;j++) int i=5 printf("i=%dn', i); printf("f%d\n", i); return 0;
Please try to explain the answers as well. It will be highly appreciated. Output of the following expression: 5 * 4 % 2 = ? Output of a loop: Example: What will be the output of the Java code (Assume all variables are properly declared.) num = 10; while (num <= 32) num = num + 5; System.out.println(num); What will be the output of the Java code (Assume all variables are properly declared.) public class test { ...
Please, explain your answer clearly (step-by-step) What output does this loop generate? int j = 1; do { int value = j * 2; j++; cout << value << ", "; } while (j <= 5); What is the output of the following code snippet? int my_fun (int A[], int size) { int result = 0; for (int i = 0; i < size; i++) { result = result + A[i]; } return result; } int main() { int...