图拉丁吧 关注:7,614,362贴子:128,590,067
  • 5回复贴,共1
#include <stdio.h>#include <string.h>
// 日期结构体定义struct data { int year, month, day;};
// 学生信息结构体定义struct std_info { char no[lbk]10[rbk]; char name[lbk]10[rbk]; char sex; struct data birthday; int score[lbk]4[rbk]; float ave;};
// 显示一个学生的信息void display(struct std_info student) { printf("Student Number: %s\n", student.no); printf("Student Name: %s\n", student.name); printf("Sex: %c\n", student.sex); printf("Birthday: %d-%d-%d\n", student.birthday.year, student.birthday.month, student.birthday.day); printf("Scores: "); for (int i = 0; i < 4; i++) { printf("%d ", student.score[lbk]i[rbk]); } printf("\nAverage: %.2f\n", student.ave);}
// 输入一个学生的信息void input(struct std_info *student) { printf("Enter student number: "); scanf("%s", student->no); printf("Enter student name: "); scanf("%s", student->name); printf("Enter sex (M/F): "); scanf(" %c", &student->sex); printf("Enter birthday (YYYY-MM-DD): "); scanf("%d-%d-%d", &student->birthday.year, &student->birthday.month, &student->birthday.day); printf("Enter scores for 4 subjects: "); for (int i = 0; i < 4; i++) { scanf("%d", &student->score[lbk]i[rbk]); } student->ave = 0; for (int i = 0; i < 4; i++) { student->ave += student->score[lbk]i[rbk]; } student->ave /= 4;}
int main() { struct std_info students[lbk]3[rbk]; // 假设我们需要输入3名学生的信息
// 输入学生信息 for (int i = 0; i < 3; i++) { printf("\nInput information for student %d:\n", i + 1); input(&students[lbk]i[rbk]); }
// 显示学生信息 for (int i = 0; i < 3; i++) { printf("\nStudent %d Information:\n", i + 1); display(students[lbk]i[rbk]); }
return 0;}


IP属地:安徽来自Android客户端1楼2024-11-27 16:28回复
    #include <stdio.h>
    #include <string.h>
    // 日期结构体定义
    struct data {
    int year, month, day;
    };
    // 学生信息结构体定义
    struct std_info {
    char no[10];
    char name[10];
    char sex;
    struct data birthday;
    int score[4];
    float ave;
    };
    // 显示一个学生的信息
    void display(struct std_info student) {
    printf("Student Number: %s\n", student.no);
    printf("Student Name: %s\n", student.name);
    printf("Sex: %c\n", student.sex);
    printf("Birthday: %d-%d-%d\n", student.birthday.year, student.birthday.month, student.birthday.day);
    printf("Scores: ");
    for (int i = 0; i < 4; i++) {
    printf("%d ", student.score[i]);
    }
    printf("\nAverage: %.2f\n", student.ave);
    }
    // 输入一个学生的信息
    void input(struct std_info *student) {
    printf("Enter student number: ");
    scanf("%s", student->no);
    printf("Enter student name: ");
    scanf("%s", student->name);
    printf("Enter sex (M/F): ");
    scanf(" %c", &student->sex);
    printf("Enter birthday (YYYY-MM-DD): ");
    scanf("%d-%d-%d", &student->birthday.year, &student->birthday.month, &student->birthday.day);
    printf("Enter scores for 4 subjects: ");
    for (int i = 0; i < 4; i++) {
    scanf("%d", &student->score[i]);
    }
    student->ave = 0;
    for (int i = 0; i < 4; i++) {
    student->ave += student->score[i];
    }
    student->ave /= 4;
    }
    int main() {
    struct std_info students[3]; // 假设我们需要输入3名学生的信息
    // 输入学生信息
    for (int i = 0; i < 3; i++) {
    printf("\nInput information for student %d:\n", i + 1);
    input(&students[i]);
    }
    // 显示学生信息
    for (int i = 0; i < 3; i++) {
    printf("\nStudent %d Information:\n", i + 1);
    display(students[i]);
    }
    return 0;
    }


    IP属地:安徽来自Android客户端2楼2024-11-27 16:36
    回复
      #include <stdio.h>
      struct address {
      char street[50];
      int zipcode;
      };
      struct friend {
      char name[32];
      int age;
      char phone[13];
      struct address addr; // 填补空缺1
      } fri[10]; // 填补空缺2
      int main(void) {
      int i, count1, count2, count3;
      count1 = count2 = count3 = 0;
      for(i = 0; i < 10; i++) {
      scanf("%s %d %s", fri[i].name, &fri[i].age, fri[i].phone);
      if(fri[i].age > 56) count1++;
      else if(fri[i].age > 39) count2++;
      else count3++;
      }
      printf("老年人数: %d, 中年人数: %d, 青年人数: %d\n", count1, count2, count3);
      return 0;
      }


      IP属地:安徽来自Android客户端7楼2024-12-04 16:16
      回复
        #include <stdio.h>
        // 首先声明address结构体
        struct address {
        char street[50];
        int zipcode;
        };
        // 然后声明friend结构体,并在其中嵌入address结构体的实例
        struct friend {
        char name[32];
        int age;
        char phone[13];
        struct address addr; // 这里嵌入address结构体
        } fri[10]; // 声明一个包含10个friend结构体的数组
        int main(void) {
        int i, count1, count2, count3;
        count1 = count2 = count3 = 0;
        for(i = 0; i < 10; i++) {
        scanf("%31s %d %12s", fri[i].name, &fri[i].age, fri[i].phone); // 限制输入长度以防止缓冲区溢出
        if(fri[i].age > 56) count1++;
        else if(fri[i].age > 39) count2++;
        else count3++;
        }
        printf("老年人数: %d, 中年人数: %d, 青年人数: %d\n", count1, count2, count3);
        return 0;
        }


        IP属地:安徽来自Android客户端8楼2024-12-04 16:19
        回复
          #include <iostream>
          using namespace std;
          int main() {
          int rows;
          cout << "请输入图形的行数:";
          cin >> rows;
          for (int i = 1; i <= rows; ++i) {
          cout << " " << string(10, ' ') << string(i, '*') << endl;
          }
          return 0;
          }


          IP属地:安徽来自iPhone客户端11楼2024-12-18 16:21
          回复
            c
            #include <stdio.h>
            int main() {
            int n, i, j;
            // 获取用户输入行数
            scanf("%d", &n);
            for (i = 1; i <= n; i++) {
            // 输出10个空格
            for (j = 0; j < 10; j++)
            putchar(' ');
            // 输出每行的空格和*
            for (j = 0; j < n - i; j++)
            putchar(' ');
            for (j = 0; j < 2 * i - 1; j++)
            putchar('*');
            putchar('\n');
            }
            return 0;
            }


            IP属地:安徽来自Android客户端12楼2024-12-18 16:38
            回复