首页 > 代码库 > 抄写例题作业:

抄写例题作业:

技术分享

#in clude<stdio.h>
#include<stdlib.h>
main()
{
struct student
{int num;
char name[20];
char sex;
int age;
float score;
char addr[30]; 
};
}
运行结果
-------------------------------- Process exited after 0.01458 seconds with return value 0 请按任意键继续
#include<stdio.h>
#include<stdlib.h>
main()
{
struct Date 
{
int month;
int day;
int year;
};
struct Student 
{
int num;
char name[20];
char sex;
int age;
struct Date birthday;
char addr[30];
};
}
#include<stdio.h>
#include<stdlib.h>
main()
{

struct Student 
{
int num;
char name[20];
char sex;
int age;
float score;
char addr[30];
}student1,student2;}
#include<stdio.h>
#include<stdlib.h>
main()
{struct Student
{long int num;
char name[20];
char sex;
char addr[20]; 
}a={10101,"zhang",m,"harbin"};
printf("NO.;%ld\nname:%s\nsex:%c\naddress:%s\n",a.num,a.name,a.sex,a.addr);
return 0;}
运行结果
 NO.;10101 name:zhang sex:m address:harbin -------------------------------- Process exited after 0.01896 seconds with return value 0 请按任意键继续. . .
#include<stdio.h>
#include<stdlib.h>
main()
{struct Student
{int num;
char name[20];
float score;
}student1,student2;
scanf("%d,%s,%f",&student1.num,&student1.name,&student1.score);
scanf("%d,%s,%f",&student2.num,&student2.name,&student2.score);
printf("The higher score is:\n");
if(student1.score>student2.score)
printf("%d,%s,%f",student1.num,student1.name,student1.score);
else if(student1.score<student2.score)
printf("%d,%s,%f",student2.num,student2.name,student2.score);
else
{printf("%d,%s,%f",student1.num,student1.name,student1.score);
printf("%d,%s,%f",student2.num,student2.name,student2.score);
}
return 0;}
#include<string.h>
#include<stdio.h>
struct person
{
char name[20];
int count;
}leader[3]={"zhang",0,"jun",0,"jie",0};
int main()
{
int i,j;
char leader_name[20];
for(i=1;i<=10;i++)
{
scanf("%s",leader_name);
for (j=0;j<3;j++)
if (strcmp(leader_name,leader[j].name)==0)leader[j].count++;
}
printf("\nResult:\n");
for(i=0;i<3;i++)
printf("%5s:%d\n",leader[i].name,leader[i].count);}
#include <stdio.h>
struct student
{
int num;
char name[20];
float score;
};
int main()
{
struct student stu[5]={{ 10106"1",",99},{10101,"z"",88},{10108,"1",74.5},{ 10110,"s",10},{ 10113,"w",8}};
struct student temp;
const int n=5;
int i,j,k;
printf("The order is:\n");
for(i=0;i<n-1;i++)
{k=i;
for(j=i+1;j<n;j++)
if(stu[j].score>stu[k].score)
k=j;
temp=stu[k];stu[k]=stu[i];stu[i]=temp;
}
for(i=0;i<n;i++)
printf("%6d %8s %6.2f\n",stu[i].num,stu[i].name,stu[i].score);
printf("\n");
return 0;}
运行结果
The order is: 10106 l 99.00 10101 z 88.00 10108 l 74.50 10110 s 10.00 10103 w 8.00 -------------------------------- Process exited after 0.01733 seconds with return value 0 请按任意键继续. . . .
#include <stdio.h>
#include <string.h>
int main()
{
struct student
{
long num;
char name[20];
char sex;
float score;
};
struct student stu1;
struct student *p;
p=&stu1;
stu1.num=10101;
strcpy(stu1.name, "Lin"); 
stu1.sex=M;
stu1.score=89.5;
printf("No.:%1d\nname:%s\nsex:%c\nscore:%5.1f\n",stu1.num,stu1.name,stu1.sex,stu1.score);
printf("\nNo.:%1d\nname:%s\nsex:%c\nscore:%5.1f\n",(*p).num,(*p).name,(*p).sex,(*p).score);
return 0;}
运行结果
 No.:10101 name: Lin sex:M score: 89.5 No.:10101 name: Lin sex:M score: 89.5 -------------------------------- Process exited after 0.01986 seconds with return value 0 7
#include <stdio.h>
#include <string.h>
int main()
{
struct student
{
long num;
char name[20];
char sex;
float score;
};
struct student stu1;
struct student *p;
p=&stu1;
stu1.num=10101;
strcpy(stu1.name, "Li Lin"); 
stu1.sex=M;
stu1.score=89.5;
printf("No.:%1d\nname:%s\nsex:%c\nscore:%5.1f\n",stu1.num,stu1.name,stu1.sex,stu1.score);
printf("\nNo.:%1d\nname:%s\nsex:%c\nscore:%5.1f\n",(*p).num,(*p).name,(*p).sex,(*p).score);
return 0;}
运行结果
No. Name sex age 10101 zahng M 18 10102 Zhang M 19 10103 Wang F 20 -------------------------------- Process exited after 0.01573 seconds with return value 0 请按任意键继续. . .
#include<stdio.h>
#define N 3 
struct Student//声明结构体类型 struct person 
{
int num;
char name[20];
float score[3];//三门课成绩 
float aver;//平均成绩 
};
int main()
{void input(struct Student stu[]);
struct Student max(struct Student stu[]);
void print(struct Student stu);
struct Student stu[N],*p=stu;//定义结构体数组和指针 
input(p);//调用input函数 
print(max(p));//调用print函数,以max函数的返回值作为实参 
return 0;
}
void input(struct Student stu[])
{int i;
printf("请输入个学生的信息:学号,姓名,三门课成绩:\n");
for(i=0;i<N;i++)
{scanf("%d,%s,%f,%f,%f",&stu[i].num,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);//输入数据 
stu[i].aver=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3.0;//求平均值 
}
}
struct Student max(struct Student stu[])
{int i,m=0;//用m存放成绩最高的学生在数组中的序号 
for(i=0;i<N;i++)
if(stu[i].aver>stu[m].aver)m=i;
return stu[m];//返还值包含该生信息的结构体元素 
}
void print(struct Student stud)
{printf("\n成绩最好的学生是:\n");
printf("学号:%d\姓名:%s\n三门课成绩:%5.1f,%5.1f,%5.1f\n平均成绩:%6.2f,stud.num,stud.name,stud.score[0],stud.score[1],stud.score[2],stud.aver");}

总结

通过本次作业 熟悉了代码的特点 敲代码更快了

不断的反复修改提升了自己的编程能力

今后应该多多联系 争取学号c语言 

抄写例题作业: