1. Code transformation Before a program written in C can be executed on a comput
ID: 669101 • Letter: 1
Question
1. Code transformation
Before a program written in C can be executed on a computer, what step is required to be done first? Briefly explain this step.
2. Basic I/O in C
Write a few lines of code that will accomplish the following:
Ask user to enter his/her birth year and height in meters (e.g. 1.74). For every field to be filled in, print on the screen message "Enter your WXYZ: ", where WXYZ should be replaced by birth year and so on.
Print on screen on different lines the collected information with a message "Your WXYZ is " followed by the respective field WXYZ.
3. Operators
What is the value each of the following C expressions evaluate to? For parts (1) to (4), assume a and b have been initialized with 0x1234 and 0x5678, respectively; for part (5), assume the values of a and b are 123410 and 567810, respectively. Write your answers as hexadecimal numbers.
a | b
a ^ b
~a
a & b
a & b
Explanation / Answer
Code transformation
2)
#include <stdio.h>
int main(void) {
char str[20];
float height;
printf("%s","Enter your Birth Year : ");
scanf("%s",&str);
printf("%f","Enter your Height : ");
scanf("%f",&height);
printf("%s %s"," Your Birth Year is",str);
printf("%s %f %s","Your Height is ",height, " Meters");
return 0;
}
3.
#include <stdio.h>
int main(void) {
int x = 0x1234;
int y = 0x5678;
printf("%d ",x|y);
printf("%d ",~x);
printf("%s ",x&y);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.