7-1 Calculation of Employee Wages
Design Ideas
(1)
1. Carefully observe the meaning of the question and sort out the general steps on the paper;
2. Design the program and write it;
- Run it after the end to see if the answers and requirements are consistent.
(2)
Flowchart: none
(3)
Experimental code
#include<stdio.h>
#include<string.h>
int main()
{
struct nam
{char name[10];
float a;
float b;
float c;
}stu[10000];
int N=3,i;
scanf("%d",&N);
for(i=0;i<N;i++)
scanf("%s%f%f%f",&stu[i].name,&stu[i].a,&stu[i].b,&stu[i].c);
for(i=0;i<N;i++)
printf("%s %.2f\n",stu[i].name,stu[i].a+stu[i].b-stu[i].c);
}
(4). Problems encountered in the debugging process of this question and solutions
Error message 1: When inputting 'stu[10000]', input '10000' to '100000', so that the program cannot run normally.
Error reason: unknown.
Modification method: Change '100000' to '10000'.
Git address: https://git.coding.net/liuhanyu1215/7-1.git
7-2
Calculate the average grade
(1)
Design ideas
1. Carefully observe the meaning of the question and sort out the approximate steps on paper;
2. Design the program and write it;
- Run it after the end to see if the answers and requirements are consistent.
(2)
Flowchart: none
(3)
Experimental code
#include<stdio.h>
int main()
{
struct name
{
char xh[10];
char name[10];
int cj;
}stu[10000];
int N,i;
float sum=0;
scanf("%d",&N);
for(i=0;i<N;i++)
{scanf("%s%s%d",&stu[i].xh,&stu[i].name,&stu[i].cj);
sum=sum+stu[i].cj;}
sum=sum/N*1.0;
printf("%.2f\n",sum);
for(i=0;i<N;i++)
{if (stu[i].cj<sum)
printf("%s %s\n",stu[i].name,stu[i].xh);
}
}
(4). Problems encountered in the debugging process of this question and solutions
Error message 1: When inputting char [10], inputting '10' to '5' causes the program running result to be incorrect.
Error reason: unknown
Modification method: Change 'char[5]' to 'char[10]'
.
Git address: https://git.coding.net/liuhanyu1215/7-2.git