Question

(4) 1. Simplify the following assignments/calculations if possible: a. a = 0; b = 0; c...

(4) 1. Simplify the following assignments/calculations if possible:

a. a = 0; b = 0; c = 0; d = 0; _____________________________

b. n1 = n1 % n2; _____________________________

c. n3 += 1; _____________________________

d. n4 = n5 / n4; _____________________________

2. Suppose that the statement x = 12; has already been done. What values will the following printf statements output assuming that the statements are done in the following order:

a. printf("%d\n", ++x); __________ b. printf("%d\n", x); __________ c. printf("%d\n", x--); __________ d. printf("%d\n", x); __________

Homework Answers

Answer #1

(4) 1.

(a) a=b=c=d=0; (This is a multiple assignment statment, and associativity is from right to left, 0 assigned to d first,value of d(0) is assigned to c ,and c to b, and b to a)

(b) n1%=n2 ; ( x=x%y is same as x%=y)

(c) n3++ or ++n3 ( n3 += 1, n3=n3+1, the same is done by increment operator, which increments the value of variable by 1)

(d) n4=n5/n4

2) ( a) 13 //initially x=12, then ++x , its is preincrement operator, value is first incremented and then used inside the expression. so x is incrementd to x=13 and that value will be printed.

(b) 13 // the value in the previous epression is x=13, so 13 will be printed.

(3) 13 //x=13 then x-- (its post decrement operator,value is first used in a expression and then decremented. So value will be printed first i.e 13, then its decremented. x=12

(d)12 // print the value of x, which is 12 (set in the previous expression)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1. Identify and correct the errors in each of the following statements: a) for (a =...
1. Identify and correct the errors in each of the following statements: a) for (a = 25, a <= 1, a--); {printf("%d\n", a);} b) The following code should print whether a given integer is odd or even: switch (value) {case (value % 2 == 0):puts("Even integer");case (value % 2 != 0):puts("Odd integer");} c) The following code should calculate incremented salary after 10 years: for (int year = 1; year <= 10; ++year) {double salary += salary * 0.05;}printf("%4u%21.2f\n", year, salary);...
Hint: it is sufficient to show A implies B, B implies C, C implies D, and...
Hint: it is sufficient to show A implies B, B implies C, C implies D, and D implies A, as repeated application of the hypothetical syllogism will give you A iff B iff C iff D. Using the definitions of odd and even show that the following 4 statements are equivalent: n2 is odd 1 − n is even n3 is odd n + 1 is even
1. Write a program to: Prompt the user to input an integer, a double, a character,...
1. Write a program to: Prompt the user to input an integer, a double, a character, and a string, storing each into separate variables. Then, output those four values on a single line separated by a space. Add a statement to also output in reverse. Add a statement to cast the double to an integer, and output that integer. 2. 2. Choose the statement(s) that generate(s) this output: I wish you were here a. printf("I wish", "you were here"); b....
Question Rewrite the following C program using switch-case statement. and give me an output please use...
Question Rewrite the following C program using switch-case statement. and give me an output please use printf and scanf #include<stdio.h> int main(void) {      int semester;           printf("What is your Studying Level (1-8)?> ");      scanf("%d" , &semester);      if(semester == 1 || semester == 2)           printf("Your are a freshman!\n ");      else if(semester == 3 || semester == 4)           printf("Your are sophomore!\n ");      else if(semester == 5 || semester == 6)           printf("Your are...
(5 pts.) Consider the C program below. Recall that fflush() just forces the printed value to...
(5 pts.) Consider the C program below. Recall that fflush() just forces the printed value to be output immediately. (For space reasons, we are not checking error return codes, so assume that all functions return normally.) int main () {    if (fork() == 0) {        if (fork() == 0) {           printf("3"); fflush(stdout);        }        else {           pid_t pid; int status;           if ((pid = wait(&status)) > 0) {                  printf("4"); fflush(stdout);           }        }...
SF = square feet of the house PY: 0 = no pool, 1 = pool BY:...
SF = square feet of the house PY: 0 = no pool, 1 = pool BY: 0 = not made of bricks, 1 made of bricks There are three neighborhoods N1, N2 and N3 y = house price Regression Statistics Multiple R 0.91 R Square 0.84 Adjusted R Square 0.83 Standard Error 20,949.15 Observations 301.00 ANOVA df SS MS F Significance F Regression 4.00 667,427,645,418.08 166,856,911,354.52 380.20 0.00 Residual 296.00 129,904,621,849.66 438,866,965.71 Total 300.00 797,332,267,267.74 Coefficients Standard Error t Stat...
1.) 2-bit binary numbers represent the values 0..3 with the following encoding: Encoding [1:0] Value 0...
1.) 2-bit binary numbers represent the values 0..3 with the following encoding: Encoding [1:0] Value 0 0 0 0 1 1 1 0 2 1 1 3 Develop the simplest Sum-of-Products equation possible that, when given two 2-bit binary numbers X[1:0] and Y[1:0], will output whether the value of X is greater than the value of Y. 2.) Assume that we have already implemented the solution to problem #1 as a module “isGreater(F, X, Y)” in Verilog, and cannot change...
Write a C++ program that would report all of the Min and Max. example: 1. 95...
Write a C++ program that would report all of the Min and Max. example: 1. 95 2. 95 3. 80 4. 80 lowest 80 on test(s): 3, 4 highest 95 on test(s): 1, 2 I have started it, however, this only outputs one of the Min and Max and not all of the other instances. #include<iostream> using namespace std; int main() { int grades[10] , min , max , minIndex , maxIndex ; int n , choice , rt ,...
int i,sum=0;   int array[8]={//You decide this};   int *a,*b,*c;   a = array;   b = &array[3];   c =...
int i,sum=0;   int array[8]={//You decide this};   int *a,*b,*c;   a = array;   b = &array[3];   c = &array[5];   c[-1] = 2;   array[1] = b[1]-1;   *(c+1) = (b[-1]=5) + 2;   sum += *(a+2) + *(b+2) + *(c+2);   printf("%d %d %d %d\n", sum, array[b-a], array[c-a], *a-*b); array[8]={ ?? }; what is array[8]?
For the following sample of n =8 scores: 0, 1, 1/2, 0, 3, 1/2 , 0,...
For the following sample of n =8 scores: 0, 1, 1/2, 0, 3, 1/2 , 0, 1 a. Simplify the arithmetic by first multiplying each score by 2 to obtain a new sample. Then, compute the mean and standard deviation for the new sample. b. Starting with the values you obtained in part a, make the correction for having multiplied by 2 to obtain the values for the mean and standard deviation for the original sample