Advertisement
cd62131

Eto 干支

Dec 12th, 2013
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.44 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. typedef struct profile {
  4.     char idnumber[8]; /*学籍番号*/
  5.     int age; /*年齢*/
  6.     int year; /*生年月日*/
  7.     int month;
  8.     int day;
  9.     int num;
  10.     int height; /*身長*/
  11.     int weight; /*体重*/
  12.     double bmi; /*BMI*/
  13. } profile_t;
  14.  
  15. void print_profile(struct profile x);
  16. profile_t input_profile(void);
  17. char *eto(int year);
  18.  
  19. int main(void) {
  20.     profile_t data;
  21.  
  22.     data = input_profile();
  23.     print_profile(data);
  24.  
  25.     getchar();
  26.     return 0;
  27. }
  28.  
  29. void print_profile(profile_t x) {
  30.     printf("%10s:%3d,%3d/%d/%d,", x.idnumber, x.age,x.year, x.month, x.day);
  31.     printf("%s,", eto(x.year));
  32.     printf("%3d,%3d,%.1f\n", x.height, x.weight, x.bmi);
  33. }
  34.  
  35. profile_t input_profile(void) {
  36.     struct profile x;
  37.  
  38.     printf("学籍番号:");
  39.     scanf("%7s",x.idnumber);
  40.     printf("年齢:");
  41.     scanf("%d",&x.age);
  42.     printf("生年月日\n");
  43.     printf("年(西暦):");
  44.     scanf("%d",&x.year);
  45.     printf("月:");
  46.     scanf("%d",&x.month);
  47.     printf("日:");
  48.     scanf("%d",&x.day);
  49.     printf("身長:");
  50.     scanf("%d",&x.height);
  51.     printf("体重:");
  52.     scanf("%d",&x.weight);
  53.  
  54.     x.bmi = (double)(100 * x.weight) / (x.height * x.height) * 100;
  55.  
  56.     getchar();
  57.     return x;
  58. }
  59.  
  60. char* eto_c[] = { "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申",
  61.     "酉", "戌", "亥" };
  62.  
  63. char *eto(int year) {
  64.     return eto_c[(year - 1900) % 12];
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement