//
// Created by hengxin on 9/30/22.
//
#include <stdio.h>
#include <math.h>
#include <ctype.h>
int main() {
char first_name[] = "Tayu";
char last_name[] = "Lo";
char gender = 'm';
int birth_year = 1954;
int birth_month = 7;
int birth_day = 20;
char weekday[] = "Tuesday";
int c_score = 50;
int music_score = 99;
int medicine_score = 78;
double mean = (c_score + music_score + medicine_score) / 3.0;
double sd = sqrt((pow(c_score - mean, 2)
+ pow(music_score - mean, 2)
+ pow(medicine_score - mean, 2)) / 3.0);
int rank = 10;
printf("%s %s \t %c\n"
"%.2d-%d-%d \t %.3s.\n"
"C = %d \t Music = %d \t Medicine = %d\n"
"Mean = %.1f \t SD = %.2f \t Rank = %d%%\n",
first_name, last_name, toupper(gender),
birth_month, birth_day, birth_year, weekday,
c_score, music_score, medicine_score,
mean, sd, rank);
return 0;
}
This code is a program that prints out information about a person, including their name, gender, birthdate, and scores in different subjects. Now let's break down the code:
1.The code includes three header files: <stdio.h>, <math.h>, and <ctype.h>. These header files provide functions for input/output, mathematical calculations, and character handling, respectively.
2.In the main() function, several variables are declared and initialized with relevant information about a person. These variables include first_name, last_name, gender, birth_year, birth_month, birth_day, weekday, c_score, music_score, medicine_score, mean, sd, and rank.
3.The mean variable is calculated by summing the three subject scores and dividing by 3.0 to find the average.
4.The sd variable is calculated using the mathematical formula for standard deviation. It calculates the square root of the average of the squared differences between each score and the mean.
5.The rank variable is set to 10%.
6.The printf() function is used to print out the person's information in a formatted manner. It displays the first and last names, gender (converted to uppercase using toupper() function), birthdate in the format MM-DD-YYYY, weekday, subject scores, average, standard deviation, and rank.
7.Finally, the program returns 0 to indicate successful execution.
Overall, this code defines variables to store information about a person and uses printf() to display that information in a formatted manner.