This is the problems for unix, Please make sure the answer is correct, thank u!
ID: 3589846 • Letter: T
Question
This is the problems for unix, Please make sure the answer is correct, thank u!
(a) (4 marks) In which phase of compilation is the following line of a C program processed: #include and how it affects further compilation? (b) (4 marks) Describe what happens when the following scanf statement: scanf ("%d%d%d", &i;, &j;, &k;); reads the folowing input: 1.2.3 What is the return value of the scanf function? ata Iine is provided in input as follows: 2017/10/06 23.45 Write a scanf statement to read the numbers above in the integer variables (y, m, and d) and one floating point variable (x), so the assigned values after scanf are as follows: y-2017 m-10 d-06 x-23.45 (d) (4 marks) Assume that four variables are given as in part (c). Write a printf statement with the integer variables y, m, d, and the floating point variable x, to produce an output as analysed in part (c), e.g., somethink like 2017/10/06 23.45 Have in mind that the variables m and d must have two digits with possibly a leading 0, and the variable x must be printed with the precisio of two digits.Explanation / Answer
1)
In compilation during the stage of preprocessor at starting of program, #include is replaced by it's text/content.
2)
scanf reads the values 1,2,3 and stores in i,j,k respectively.
And the return of scanf will be number of items read. i.e. 3 in this case.
3)
int y,m,d;
float x;
// %d to read int and %f to read float
scanf("%d%d%d%f",&y,&m,&d,&x);
4)
// %02d adds a leading zero if length less than 2. %.2f prints only two decimal places
printf("%d/%02d/%02d %.2f ",y,m,d,x);
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.