编译器:Dev-c
/*第1题*/
#include <stdio.h>
struct date{
int year;
int month;
int day;
};
int main(int argc, char const *argv[])
{
struct date today;
scanf("%d %d %d", &today.year, &today.month, &today.day);
int total = 0, i;
int b[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if (today.month == 1)
printf("今天是今年的第 %d 天\n", today.day);
else
{
if ( (today.year%4 == 0 && today.year %100 !=0) || today.year%400 == 0)
{
b[1] = 29;
for (i = 0; i < today.month - 1; i++)
total += b[i];
printf("今天是第 %d 天\n", total + today.day);
}else{
for (i = 0; i < today.month - 1; i++)
total += b[i];
printf("今天是第 %d 天\n", total + today.day);
}
}
return 0;
}
/*第2题*/
#include <stdio.h>
struct date{
int year;
int month;
int day;
};
int days(struct date a);
int main(int argc, char const *argv[])
{
struct date today;
scanf("%d %d %d", &today.year, &today.month, &today.day);
int x = days(today);
printf("今天是今年的第 %d 天\n", x);
return 0;
}
int days(struct date a)
{
int total = 0, i;
int b[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if (a.month == 1)
printf("今天是今年的第 %d 天\n", a.day);
else
{
if ( (a.year%4 == 0 && a.year %100 !=0) || a.year%400 == 0)
{
b[1] = 29;
for (i = 0; i < a.month - 1; i++)
total += b[i];
}else{
for (i = 0; i < a.month - 1; i++)
total += b[i];
}
}
return total;
}
/*第3、4题*/
#include <stdio.h>
struct Student{
int num;
char name[20];
int score[3];
}stu[5];
int N = 5;
void input(struct Student stu[]); //输入数据
void print(struct Student stu[]); //打印数据
int main(int argc, char const *argv[])
{
input(stu);
print(stu);
return 0;
}
void input(struct Student stu[])
{
int i;
printf("请依次输入各个学生的学号,姓名,三科成绩:\n");
for (i = 0; i < 5; i++)
scanf("%d %s %d %d %d", &stu[i].num, &stu[i].name,
&stu[i].score[0], &stu[i].score[1], &stu[i].score[2]);
}
void print(struct Student stu[])
{
int i;
for (i = 0; i < 5; i++)
{
printf("num name score1 score2 score3\n");
printf("%-6d%-6s%-8d%-8d%-8d\n", stu[i].num, stu[i].name,
stu[i].score[0], stu[i].score[1], stu[i].score[2]);
}
}
/*第5题*/
#include <stdio.h>
struct Student{
int num;
char name[20];
int score[3];
int average;
}stu[10];
int N = 10;
void input(struct Student stu[]); //输入数据
void print(struct Student stu[]); //打印平均成绩
void max(struct Student stu[]); //输出最高同学的数据
int main(int argc, char const *argv[])
{
input(stu);
print(stu);
max(stu);
return 0;
}
void input(struct Student stu[])
{
int i;
printf("请依次输入各个学生的学号,姓名,三科成绩:\n");
for (i = 0; i < N; i++)
{
scanf("%d %s %d %d %d", &stu[i].num, &stu[i].name,
&stu[i].score[0], &stu[i].score[1], &stu[i].score[2]);
stu[i].average = (stu[i].score[0] + stu[i].score[1] + stu[i].score[2]) / 3;
}
}
void print(struct Student stu[])
{
int i;
printf("num name average\n");
for (i = 0; i < N; i++)
printf("%-6d%-6s%-8d\n", stu[i].num, stu[i].name, stu[i].average);
}
void max(struct Student stu[])
{
int i, m = 0;
for (i = 0; i < N; i++)
if (stu[i].average > stu[m].average)
m = i;
printf("\n成绩最好的同学:\n");
printf("num name score1 score2 score3 average\n");
printf("%-6d%-6s%-8d%-8d%-8d%-8d", stu[m].num, stu[m].name, stu[m].score[0],
stu[m].score[1], stu[m].score[2], stu[m].average);
}
待添加…