例题编写

Posted 米粒呀

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了例题编写相关的知识,希望对你有一定的参考价值。

例9.1程序

#include<stdio.h>
#include<stdlib.h>
int main()
{
    struct student
    {
    long int num;
    char name[20];
    char sex;
    char addr[20];
}
a={1,"sun",m,"123 beijing road"};
printf("NO.:%ld\n name:%s\n sex:%c\n addr:%s\n",a.num,a.name,a.sex,a.addr);
return 0;
    
     
}

运行结果

NO.:1
 name:sun
 sex:m
 addr:123 beijing road

--------------------------------
Process exited after 0.006787 seconds with return value 0
请按任意键继续. . .

例9.2

#include<stdio.h>
#include<stdlib.h>
int main()
{
    struct student
    {
    long 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 %6.2f\n",student1.num,student1.name,student1.score);
else if(student1.score<student2.score)
printf("%d %s %6.2f\n",student2.num,student2.name,student2.score);
else{
printf("%d %s %6.2f\n",student1.num,student1.name,student1.score);
printf("%d %s %6.2f\n",student2.num,student2.name,student2.score);    
}
return 0;
}

运行结果:

189
290
The higher score is:
290.00

--------------------------------
Process exited after 78.92 seconds with return value 0
请按任意键继续. . .

例9.3:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
    struct person
    {
    char name[20];
    int count;
}leader[3]={"li",0,"sun",0,"zhang",0};
int main()
{int i,j;
char leader_name[20];
for(i=0;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("\n Result:\n");
    for(i=0;i<3;i++)
    printf("%5s:%d\n",leader[i].name,leader[i].count);
    

    

return 0;
}

运行结果:

sun
li
liu
sun
li
li
liu
sun
li
lisun
li

 Result:
   li:5
  sun:3
zhang:0

--------------------------------
Process exited after 2.568 seconds with return value 0
请按任意键继续. . .

例9.4:

 

以上是关于例题编写的主要内容,如果未能解决你的问题,请参考以下文章

编写代码片段的更简洁的方法

VS Code配置snippets代码片段快速生成html模板,提高前端编写效率

线段树详解

我们可以在活动 xml 中编写 UI 以及在片段 xm 中编写 UI 吗?

片段中 ListView 的 setOnItemClickListener

例题编写