Please show detailed working and answer all of the following C programing questi
ID: 3832081 • Letter: P
Question
Please show detailed working and answer all of the following C programing questions below:
Answer each of the following. Assume all variables are properly declared. Given the following program fragment, determine the value of result: int int two = 17; double result = one/(double) two; Write a C statement so the variable profit is displayed in a field of 12 spaces, in fixed point notation, with a decimal point and four decimal digits. Write a C logical expression that is false if either x or y is equal to 5 Rewrite the following if statement as an equivalent switch statement. if (digit = = 0) value = 3; else if (digit = = 1) value = 3; else if (digit = = 2) value = 6; else if (digit = = 3) value = 9; The following code segment displays: v1 = 15.0; v2 = 0.5; if (v1 > 10.0) printf("ten "); else if (v1 > 14.0) printf("fourteen "); if (v2 * v1 > 7.0) printf("seven "); if (v1 - v2 > 9.0) printf("nine "); printf(" ");Explanation / Answer
1)
> two = 17
result = 4/17
result = 0.235294117
although 4 is integer but there is automatic upcast and result will be in double.
2) x==y==5 ? false : true
Here x and y both will be compared to 5 and if equal then logical operation will result in false else true.
3) We can rewrite in switch statement as follows
switch(digit)
{
case 0 :
value = 3;
break;
case 1:
value = 3;
break;
case 2 :
value = 6;
break;
case 3 :
value = 9;
break;
}
4) It will first compare with first if which is true hence it will print ten and will not go in else if
but again we have another if which is not connected to first if ladder now v1*v2 is 7.5 which is greater than 7.0 hence it will print seven.
Then again check for third if v1-v2 is 14.5 which is greater than 9.0 hence it will print nine
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.