抄写例题

#include<stdio.h>
struct Student
{
    long int num;
    char name[30];
    char sex;
    char addr[100];

};
int main()
{
    struct Student a={10101,"LiLin",‘M‘,"123 bei jing road"};
    printf("num:%d\nname:%s\nsex:%c\naddr:%s\n",a.num,a.name,a.sex,a.addr);
}
1

结果:

num:10101 name:LiLin sex:M addr:123 bei jing road

-------------------------------- Process exited after 0.4208 seconds with return value 50 请按任意键继续. . .
#include<stdio.h>
struct stu
{
    int num;
    char name[30];
    float score;
};
int main()
{
    struct stu student1,student2;
    scanf("%d%s%f",&student1.num,student1.name,&student1.score);
    scanf("%d%s%f",&student2.num,student2.name,&student2.score);
    if(student1.score>student2.score)
    printf("%d  %s  %6.2f",student1.num,student1.name,student1.score);
    else if(student1.score<student2.score)
    printf("%d  %s %6.2f",student2.num,student2.name,student2.score);
    else
    {
    printf("%d  %s  %6.2f",student1.num,student1.name,student1.score);
    printf("%d  %s  %6.2f",student2.num,student2.name,student2.score);
    }
}

2

结果:

001 ke 77 002 fe 99 2  fe  99.00 -------------------------------- Process exited after 36.61 seconds with return value 12 请按任意键继续. . .

#include<string.h>
#include<stdio.h>
struct people
{
    char name[20];
    int count;
};
int main()
{
     struct people a[3]={{"zhao",0},{"li",0},{"sun",0}};
     int i,j;
     char b[40];
     for(i=0;i<=10;i++)
     {scanf("%s",b);
      for(j=0;j<3;j++)
      if(strcmp(b,a[j].name)==0)
         a[j].count++;
     }
      for(i=0;i<3;i++)
      {printf("%s,%d\n",a[i].name,a[i].count);}
       return 0;
}

3,

结果:

zhao li li zhao sun sun zhao li li zhao zhao zhao,5 li,4 sun,2

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

#include<stdio.h>
struct student
{
    int num;
    char name[20];
    float score;
};
int main()
{
   struct student Stu[5]={{10101,"Zhang",78},
                          {10103,"Wang",98.5},
                          {10106,"Li",86},
                          {10108,"Ling",73.5},
                          {10110,"Sun",100}};
    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;
}

4

结果:

The order is:  10110      Sun 100.00  10103     Wang  98.50  10106       Li  86.00  10101    Zhang  78.00  10108     Ling  73.50

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

#include<stdio.h>
#include<string.h>
struct Student
{
    long num;
    char name[20];
    char sex;
    float score;
};
int main()
{
    struct Student stu_1;
    struct Student   *p;
    p=&stu_1;
    stu_1.num=10101;
    strcpy(stu_1.name,"Li Lin");
    stu_1.sex=‘M‘;
    stu_1.score=89.5;
    printf("NO:%ld\nname:%s\nsex:%c\nscore:%5.1f\n",
            stu_1.num,stu_1.name,stu_1.sex,stu_1.score);
    printf("\nNO:%ld\nname:%s\nsex:%c\nscore:%5.1f\n",
           (*p).num,(*p).name,(*p).sex,(*p).score);
    return 0;
}

5

结果:

NO:10101 name:Li Lin sex:M score: 89.5

NO:10101 name:Li Lin sex:M score: 89.5

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

#include<stdio.h>
struct student
{
    int num;
    char name[20];
    char sex;
    int age;

};
 struct student stu[3]={{10101,"LiLin",‘M‘,10},
                        {10102,"ZhangFang",‘M‘,19},
                        {10104,"Wang Min",‘F‘,20}};
int main()
{
    struct student *p;
    printf("No    Name                 sex age\n");
    for(p=stu;p<stu+3;p++)
    printf("%5d %-20s %2c %4d\n",p->num,p->name,p->sex,p->age);
    return 0;
}

6,

结果 :

No    Name                 sex age LiLin                 M   10 ZhangFang             M   19 Wang Min              F   20

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

#include<stdio.h>
#define N 3
struct Student
{  int num;
   char name[20];
   float score[3];
   float aver;
};
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;
    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\n姓名:%s\n三门课成绩:%5.1f,%5.1f,%5.1f\n平均成绩:%6.2f\n",
       stud.num,stud.name,stud.score[0],stud.score[1],stud.score[2],stud.aver);
}
int main()
{
struct Student stu[N],*p=stu;
       input(p);
       print(max(p));
       return 0;
}

7

结果:

请输入各学生信息、学号、姓名三门课成绩: 10101 linkang 85 72 63 10102 dert 62 74 83 10103 qwer 74 76 80

学生的最高成绩是: 学号:10103 姓名:qwer 三门课成绩: 74.0, 76.0, 80.0 平均成绩: 76.67

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

时间: 2025-01-01 20:56:15

抄写例题的相关文章

抄写例题作业

例题9.1 #include<stdio.h> int main() { struct Student { long int num; char name[20]; char sex; char addr[20]; }a={10101,"Li Lin",'M',"123 Beijing Road"}; printf("NO.:%ld\nname:%s\nsex:%c\naddress:%s\n",a.num,a.name,a.sex,

抄写例题作业:

#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 请按任意键继续 #i

抄写例题作业1

例9.1: #include<stdio.h> int main() {struct Student //声明结构体类型struct Student { long int num; //以下四行为结构体的成员 char name[20]; char sex; char addr[20]; }w={01,"Yu Jinchi",'M',"Beijing Road"}; //定义结构体变量a并初始化 printf("NO.:%ld\nname:%s

例题抄写作业

例9.1 把一个学生的信息放在一个结构体变量中,然后输出这个学生的信息 #include<stdio.h> int main() { struct stu { long int num; char name[20]; char sex[3]; char addr[20]; }a={1010,"张鑫家","男","qqq"}; printf("No:%ld\nname:%s\nsex:%c\naddress:%s\n"

抄写第九章例题

例9.1 #include<stdio.h> #include<stdlib.h> main() {struct Student {long int num; char name[20]; char sex; char addr[20]; }a={10101,"li lin",'M',"123 beijing Road"}; printf("NO.;%ld\nname:%s\nsex:%c\naddress:%s\n",a

acm常见算法及例题

转自:http://blog.csdn.net/hengjie2009/article/details/7540135 acm常见算法及例题 初期:一.基本算法:     (1)枚举. (poj1753,poj2965)     (2)贪心(poj1328,poj2109,poj2586)     (3)递归和分治法.     (4)递推.     (5)构造法.(poj3295)     (6)模拟法.(poj1068,poj2632,poj1573,poj2993,poj2996)二.图算法

黑书例题 Fight Club 区间DP

题目可以在bnuoj.soj等OJ上找到. 题意: 不超过40个人站成一圈,只能和两边的人对战.给出任意两人对战的输赢,对于每一个人,输出是否可能是最后的胜者. 分析: 首先序列扩展成2倍,破环成链. dp[i][j]表示i和j能够相遇对打,那么dp[i][i+n]为真代表可以成为最后胜者. 枚举中间的k,若i和j都能和k相遇,且i和j至少一人能打赢k,那么i和j可以相遇. 复杂度o(n^3) 1 #include<cstdio> 2 #include<cstring> 3 usi

linux脚本进阶例题解析

例题一:编写脚本/root/bin/createuser.sh,实现如下功能: 使用一个用户名做为参数,如果指定参数的用户存在,就显示其存在,否则添加之:并生成8位随机口令并存在一个文件中,初步提示改口令,显示添加的用户的id号等信息 #!/bin/bash # ------------------------------------------ # Filename: useradd.sh  # Revision: null # Date: 2017-09-11 21:47:22 # Auth

JAVA基础汇总及例题详解

java语言的一个核心: jdk, java development kits---面向开发人员 jre, java Runtime Environment---服务器上 java虚拟机---(以字节码为指令的CPU)---*.class java编译器-->字节码-->类加载器进行验证-->虚拟机运行 垃圾回收机制 public class ...{ int a = 1; } c/c++垃圾回收由程序员去运行 java编程语言(一门纯面向对象)的特点: 1, 面向对象  封装  继承