#include<stdio.h>
#include<assert.h>
#include<stdlib.h>
typedef struct Day
{
int year;
int month;
int days;
}Day;
int Get_days(Day* Pday)
{
assert(Pday != NULL);
int dayofMonth[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
if ((Pday->year % 4 == 0 && Pday->year % 100 != 0) || (Pday->year % 400 == 0))
dayofMonth[1] = 29;
int count = 0;
switch (Pday->month)
{
case 12:count += dayofMonth[10];
case 11:count += dayofMonth[9];
case 10:count += dayofMonth[8];
case 9:count += dayofMonth[7];
case 8:count += dayofMonth[6];
case 7:count += dayofMonth[5];
case 6:count += dayofMonth[4];
case 5:count += dayofMonth[3];
case 4:count += dayofMonth[2];
case 3:count += dayofMonth[1];
case 2:count += dayofMonth[0];
case 1:count += 0; break;
default:
return -1;
break;
}
count += Pday->days;
return count;
}
int main()
{
Day dy = { 2021,7,28 };
int days = Get_days(&dy);
printf("%d\n", days);
Student stu[3];
int len = sizeof(stu) / sizeof(stu[0]);
return 0;
}
#include<stdio.h>
#include<assert.h>
#include<stdlib.h>
typedef struct Student
{
char num[20];
char name[20];
double score[3];
}Student;
void Input(Student* arr, int len)
{
assert(arr != NULL);
for (int i = 0; i < len; i++)
{
scanf_s("%s %s %f %f %f\n", &arr[i].num, &arr[i].name, arr[i].score[0], arr[i].score[1], arr[i].score[2]);
}
}
void Print(Student* arr, int len)
{
assert(arr != NULL);
for (int i = 0; i < len; i++)
{
printf("%s ", arr[i].num);
printf("%s ", arr[i].name);
printf("%s ", arr[i].score[0]);
printf("%s ", arr[i].score[1]);
printf("%s ", arr[i].score[2]);
}
printf("\n");
}
void StudentScore(struct Student arr[], int len)
{
assert(arr != NULL);
double total[3] = { 0 };
double* score = (double*)malloc(sizeof(double) * len);
assert(score != NULL);
for (int i = 0; i < len; i++)
{
total[0] += arr[i].score[0];
total[1] += arr[i].score[1];
total[2] += arr[i].score[2];
score[i] = arr[i].score[0] + arr[i].score[1] + arr[i].score[2];
}
printf("第一门课avg:%f\n", total[0] / len);
printf("第二门课avg:%f\n", total[1] / len);
printf("第三门课avg:%f\n", total[2] / len);
double highscore = 0;
for (int i = 0; i < len; i++)
{
if (score[i] > highscore)
{
highscore = score[i];
}
}
for (int i = 0; i < len; i++)
{
if (score[i] = highscore)
{
printf("%s ", arr[i].num);
printf("%s ", arr[i].name);
printf("%f ", arr[i].score[0]);
printf("%f ", arr[i].score[1]);
printf("%f ", arr[i].score[2]);
printf("总成绩=%f\n", score[i] / 3);
}
}
}
int main()
{
Student stu[3];
int len = sizeof(stu) / sizeof(stu[0]);
Input(stu, len);
Print(stu, len);
return 0;
}
#include<stdio.h>
#include<assert.h>
#include<stdlib.h>
#include<ctype.h>
void ShowToUpper()
{
char* path = "D:\\test.txt";
FILE* fw = fopen(path, "wb");
assert(fw != NULL);
char ch;
while ((ch = getchar()) != '!')
{
if (islower(ch))
{
ch = toupper(ch);
}
fwrite(&ch, sizeof(char), 1, fw);
}
fclose(fw);
}
void Merge(const char* pathA, const char* pathB, const char* pathC)
{
FILE* fw = fopen(pathC, "w");
FILE* frA = fopen(pathC, "r");
FILE* frB = fopen(pathC, "r");
char ch_a;
char ch_b;
int len1 = 0;
int len2 = 0;
len1 = fread(&ch_a, sizeof(char), 1, frA);
len2 = fread(&ch_b, sizeof(char), 1, frB);
while (len1 > 0 && len2 > 0)
{
if (ch_a <= ch_b)
{
fwrite(&ch_a, sizeof(char), 1, fw);
len1 = fread(&ch_a, sizeof(char), 1, frA);
}
else
{
fwrite(&ch_b, sizeof(char), 1, fw);
len2 = fread(&ch_b, sizeof(char), 1, frB);
}
}
while (len1 > 0)
{
fwrite(&ch_a, sizeof(char), 1, fw);
len1 = fread(&ch_a, sizeof(char), 1, frA);
}
while (len2 > 0)
{
fwrite(&ch_b, sizeof(char), 1, fw);
len2 = fread(&ch_b, sizeof(char), 1, frB);
}
fclose(fw);
fclose(frA);
fclose(frB);
}
int main()
{
ShowToUpper();
return 0;
}