Q4 40-50 Flashcards

1
Q

/* 40 Write a program to read a float representing a number of degrees Celsius, and print as a float the equivalent temperature in degrees Fahrenheit. Print your results in a form such as Enter a temperature is Celsius degrees: 100 100.0 degrees Celsius is equivalent to 212.0 degrees Fahrenheit */

A

include int main(void) { float C, F; printf(“Enter the temperature in Celsius: “); scanf(“%f”, &C); printf(“%5.1f degrees Celsius is %.1f degrees Fahrenheit\n”, C, F = C*2.12); return 0; }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

/* 41 Write a program that asks the user to enter an integer number of seconds, then prints as output the equivalent time in hours, minutes and seconds. */

A

int initTime, hours, minutes, seconds; printf(“Enter the number of seconds: “); scanf(“%d”, &initTime); hours = initTime/3600; minutes = (initTime % 3600) / 60; seconds = ((initTime % 3600) % 60); printf(“%d seconds is %dhr %dm %ds”, initTime, hours, minutes, seconds);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

/* 42 Where possible, write equivalents for the following statements using compound assignment operators: s = s / 5; q = q * n + 4; z = z - x * y; t = t + (u % v); */

A

s /= 5; q = q * n + 4; z -= x * y t += u % v;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

/* 43 What values are assigned to n, m, and p, given these initial values? i = 4; j = 8; n = ++i * –j; m = i + j–; p = i + j; */

A

n = 35; m = 12; p = 11;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

/* 44 What are the values of n, m, and p after the execution of this code fragment? j = 5; k = 2; n = j - ++k; m = j– + k–; p = k + j; */

A

n = 2; m = 8; p = 6;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

/* 45 What arc the values of x, y, and z after the execution of this code fragment? x = 3; y = 5; z = 2; x *= y+ z; y /= 2 * z + 1; z += x; */

A

x = 21; y = 1; z = 23;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

/* 46 Show the output produced by the following program fragment. int i = 1; int j = 2; i -= - – j; printf(“%d %d\n”, i, j); */

A

2 1; i = 2, j = 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

/* 47 Show the output produced by the following program fragment. int i = 1; int j = 2; i -= - - - j; printf(“%d %d\n”, i, j); */

A

3 2; i = 3, j = 2;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

/* 48 Show the output produced by the following program fragment. int i = 1; int j = 2; i = + + + + + j; j = - - - - - j; printf(“%d %d\n”, i, j); */

A

2, -2; i = 2, j = -2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

/* 49 Show the output produced by the following program fragment. int i = 1; int j = 2; i = - + - + - + j; printf(“%d %d\n”, i, j); */

A

-2, 2; i = -2, j = 2;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

/* 50 Show the output produced by the following program fragment. int i = 1; int j = 2; i = + - + - + - j; printf(“%d %d\n”, i, j); */

A

-2, 2 NOTE: evidently unary + does not do anything

How well did you know this?
1
Not at all
2
3
4
5
Perfectly