Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A data line is provided in input as follows: 2017/10/06 23.45 Write a scanf stat

ID: 3589311 • Letter: A

Question

A data line 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

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

#include<stdio.h>

int main()

{

int y,m,d;

float x;

scanf("%d%02d%02d%f",&y,&m,&d,&x); /* take m and d as %02d*/

printf("%d/%02d/%02d %.2f",y,m,d,x); /* print the m and d as leading 0's and x is precision tabke %.2f */

}