1. (60 points) Evaluate the following expressions. Assume: x is 10.5, y is 7.2,
ID: 3891030 • Letter: 1
Question
1. (60 points) Evaluate the following expressions. Assume: x is 10.5, y is 7.2, m is 5, n is 2 Hint: You can use printf to verify your answers. But you must know which format control character to use a. x / (double) m (double) (n * m) d. (double) (n / m) + y (double) (n / m) 35 % 6 2. (40 points) Evaluate the following expressions, assuming that letters or digits have consecutive character codes. This means that the codes for letters: ·A', ‘B', .., ‘Z' are consecutive num!bers. The codes for digits: '1, ‘2', ..,-9, are consecutive numbers. The codes for letters: ‘a', 'b,,.., are consecutive numbers. Hints: You can use printf to verify your answers. But you must know which format control character to use. Refer to the code char demo.c in Lec#4 notes. (int) 'M' - (int) J' (char) ((int) 'T' + 3) c.(int) '9' - (int) '6Explanation / Answer
#include<stdio.h>
void main(){
double x=10.5,y=7.2;
int n=2,m=5;
printf("%f ",x/(double)m); // convert m to double perform division
//2.1000
printf("%f ",x/m); // divide double by integer
//2.1000
printf("%f ",(double)(n*m)); // multiply n with m and convet to double
//10.0000
printf("%f ",(double)((n/m)+y)); // divide n with m and add y and convert to double
//7.2000
printf("%f ",(double)(n/m)); // divide n with m and convert to double (2/5 is zero)
//0.0000
printf("%d ",35%6); // get the remainder of 35 divides by 6
//5
printf("%d ", (int)'M' - (int)'J'); // ascii value of M - ascii value of J
//3
printf("%c ",(char)((int)'T' + 3)); // ascii value of T + 3
//W
printf("%d ",(int)'9' - (int)'6'); // ascii value of 9 - ascii value of 6
//3
printf("%d ",'M'-'J'); // ascii value of M - ascii value of J
//3
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.