printf(“%d %d ”, i / j, i % j);
printf(“%d”, (i + 10 ) % j);
printf("%d”, (i + 10) % k / j);
i *= j + 3;
printf(“%d %d”, i, j);
i *= j *= k;
printf(“%d %d %d”, i, j, k);
j = ++i * 3 – 2;
printf(“%d %d” i, j)
j = 3 – 2 * i++;
printf(“%d %d”, i, j);
printf(“%d ”, i++ - ++j);
printf(“%d %d”, i, j);
For the first part:
a. 3 1
(7/2=3(gives the rounded value to the lowest whole number, so 3.5 becomes 3)).
(7%2 dividing 7 with 2 will give you a remainder of 1. So % checks the remainder also known as modulo).
b. 2
(14 divided by 3 will give us a remainder of 2) Therefore 2. to check 3*4=12, So 14-12=2.(Just another way).
c. 1
(17 divided by 9 will give a remainder of 8. So 8 divided by 8 will give a quotient of 1. Therefore answer is 1.)
For the second part:
a. 77 8
This expression is also equal to i=i*(j+3). Therefore 7*(8+3)=7*11=77; and j gets printed the same so 8.
b. 1 1 1
This expression will start from the end. so k remains the same=1 j=j*k=1 and i=i*j=1;
Suppose, instead of 1 we took 4, answer would be k=4 j=j*k, so j=4*4=16 and i=i*j, so i=4*16=64.
For the Third part:
a. 5 13
Here, i is a pre-incrementation operation. So, first it will increase the value, then it will operate. So i becomes 4+1=5, and j=(5*3)-2=13.
b. 4 -3
Here, i is a post-incrementation operation. So, it will increase its value after the operation is over. So, the expression for j=3-2*3=-3 and then i will increase its value, therefore i=4;
c. -4
i is post incrementation and j is pre-incrementation. So, j will increase its value while the arithmetic operation is taking place, whereas i will increase after the arithmentic operation is over. So, 2-6=-4
3 6
Now, since the operation is over i will increase its value by 1, j has already done it during the expression so it remains the same
i=(2+1) and j=6.
Show the output produced by each of the following program fragments. Assume that I, j, k...
What is the output from each of the following segments of C++ code? Record the output after the “Answer” prompt at the end of each program fragment. Assume all variables have been suitably declared. (Each problem is worth 3 points.) 1. for (int j = 25; j > 16; j -= 3) cout << setw(5) << j; Answer: 2. int sum = 0; for (int k = -2; k <= 2; k++) sum = sum +...
What is the output of the following program? Show each step to get to the output #include <stdio.h> int f(int* a, int* b); int main() { int a = 6, b = 7, c = 8; b = f(&c, &a); printf("a = %d, b = %d, c = %d\n", a, b, c); return 0; } int f(int* a, int* b) { *a = *a + *b; *b = *a - *b; printf("a = %d,...
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;
Program 2: Thread version int i = 100; char *buffer: void *tfuc(void *noarg) { int j = 0; printf("B:1-%d, j = %d\n",1,1); printf("B: I = %d, j = %d\n",1,1); j = 3; strcpy(buffer, "red"); Pthread exit(NULL); //print the string (show values of i, j) //print the string (show values of i,1) //copy the string "red" to buffer. int main(void) { pthread_t tid; //declaring vars int j = 1; buffer strcpy(malloc(100), "blue"); //Initialize buffer and copy the "blue" to it pthread_create(&tid,...
What is the output from each of the following segments of C++ code? Record the output after the “Answer” prompt at the end of each program fragment. Assume all variables have been suitably declared. (Each problem is worth 3 points.) for (int k = 2; k < 5; k++) { for (int j = 3; j < 6; j++) cout << setw(4) << (k + j) << " "; cout << endl; }
I NEED HELP WITH THE FLOWCHART AND PSEUDOCODES OF THIS PROGRAM
PLEASE!
+3) (5 pts) Show the screen output of running the following program. #include <stdio.h> Screen output: int f1(int, int); //function declaration void f2(int); int main() { printf("calling f1( ) ..\n"); int flResult = f1(7,-8); printf("flResult = %d\n", f1Result); }//main) int f1(int a, int b) { printf("in f1(): a = %d, b = %d\n", a, b); int data = -1; if (a >b) data = a - b: return...
Compute the time complexity for each of the following two program fragments with respect to N. Show your steps in reaching your answer. 1) for(i=1; i < N; i = i*2) { for(j=0;j // Operations with constant time… } } 2) for(i = 0; i < sqrt(N); i++){ for(j=1; j < i+8; j++){ for(k=0;k // Operations with constant time… } } }
1 Rewrite the following program so that it will use function. include <stdio.h> Int main) printf ("Hello!") return 0 2 Assume a program has the following declarations: short s- 4 int i--5; long m-3 float f-19.3f; double d-3.6; What are the following values? (a) s+m (b) (float) d (c) d s (e) (int) f 3 What will be the output of the following program: int x = 3 float a 2.76; y-2* x; print f("X-2d, y*ta, z»%d", x, y, z);...
C++
What is the output of the following program? Using a pointer
diagram show the evolution of all data objects in memory. Assume
the code is embedded in a correct and complete program.
3.(8 pts) What is the output of the following program? Using a pointer diagram show the evolution of all data objects in memory. Assume the code is embedded in a correct and complete program. int array size 4, *a i a new int [array size] int *p...
OPERATING SYSTWM
Question 31 What is the output of this C program? #include #include void main() int mptr, *cptr mptr = (int*)malloc(sizeof(int)); printf("%d", "mptr); cptr = (int)calloc(sizeof(int),1); printf("%d","cptr); garbage 0 000 O garbage segmentation fault Question 8 1 pts If this program "Hello" is run from the command line as "Hello 12 3" what is the output? (char '1'is ascii value 49. char '2' is ascii value 50 char'3' is ascii value 51): #include<stdio.h> int main (int argc, char*argv[]) int...