码迷,mamicode.com
首页 > 其他好文 > 详细

例题作业

时间:2017-04-10 22:37:50      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:after   second   ted   proc   arp   难度   知识点   return   ++   

#include<stdio.h>
struct student 
{
    int num;
    char name[20];
    char sex;
    char add[20];
}stu={1,"zhang",W,"siyu"};
int main()
{
printf("%d,%s,%c,%s",stu.num,stu.name,stu.sex,stu.add);

 } 
1,zhang,W,siyu
--------------------------------
Process exited after 0.5593 seconds with return value 0
请按任意键继续. . .

  总结:

這个程序还算可以,没有太多难度,也巩固了一下自己的知识点。

例题2.

#include<stdio.h>
struct Student 
{
    int num;
    char name[20];
    int score;
}std1,std2;
int main()
{
    printf("请输入成绩:\n");
    scanf("%d %s %d",&std1.num,std1.name,&std1.score);
    scanf("%d %s %d",&std2.num,std2.name,&std2.score);
    printf("输出成绩最高同学信息\n");
    if(std1.score<std2.score)
    printf("%d,%s,%d\n",std2.num,std2.name,std2.score);
    else
    {
        if(std1.score>std2.score)
        printf("%d,%s,%d\n",std1.num,std1.name,std1.score);
        else
            printf("%d,%s,%d\n",std2.num,std2.name,std2.score);
    }
    return 0;
 } 
请输入成绩:
1 卡 66
2 期 99
输出成绩最高同学信息
2,期,99

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

  总结:

 这个程序稍有些难度,但是在运行时没有出现什么不能理解的错误。

例题3.

#include<stdio.h>
#include<string.h>
struct Person
{
    char name[20];
    int count;
 } ;
 int main()
 {
     struct Person person[3]={"",0,"",0,"",0};
     int i,j;
    char name[10];
    for(i=0;i<5;i++)
    {
        printf("请输入选择的人:");
        scanf("%s",name);
        for(j=0;j<3;j++)
        {
            if(strcmp(name,person[j].name )==0)
            person[j].count ++;
        }
        }
     for(i=0;i<3;i++)
     {
         printf("%s:%d\n",person[i].name ,person[i].count );
     }
 }
请输入选择的人:张
请输入选择的人:张
请输入选择的人:张
请输入选择的人:思
请输入选择的人:思
张:3
思:2
宇:0

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

  这个程序在票数累加时第三个for循环总是输出不对,原因:i的值在第一个for循环后未重新定义;

例题4.

#include<stdio.h>
#include<string.h>
struct STD
{
    int number;
    char name[10];
    int score;
};
 int main()
 {
     struct STD stu[5]={{1001,"",99},{1002,"",100},{1003,"",97},{1004,"",98},{1005,"",96}};
     struct STD temp;
     struct STD *p;
     p=stu;
     int i,j;
     for(j=0;j<4;j++)
     {
         for(i=0;i<4;i++,p++)
         {
            if(stu[i].score <stu[i+1].score)
           {
              temp=stu[i] ;
              stu[i] =stu[i+1] ;
              stu[i+1]=temp;
          }
        }
    }
    for(i=0;i<5;i++)
    {
         printf("%d\t%s\t%d\n",stu[i].number ,stu[i].name ,stu[i].score );
    }
}
1002    思      100
1001    张      99
1004    李      98
1003    雨      97
1005    王      96

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

  总结:

这个程序在输出的表格时忘了\t,输了几遍都不对,最后在书上找到的,i的值在输出一遍的时候才反应过来要重新赋值。

例题5.

#include<stdio.h>
#include<string.h>
struct STD
{
    int num;
    char name[20];
    char sex[3];
    int score;
};
 
 int main()
{
    struct STD stu;
    struct STD *p; 
    p=&stu;
    stu.num =1;
    strcpy(stu.name ,"");
    strcpy(stu.sex ,"M");
    stu.score =76;
    printf("正常输出:"); 
    printf("学号=%d  姓名=%s  性别=%s  成绩=%d\n",stu.num ,stu.name ,stu.sex ,stu.score );
    printf("以p-<输出:\n");
    printf("学号=%d  姓名=%s  性别=%s  成绩=%d\n",p->num ,p->name ,p->sex ,p->score );
}
正常输出:学号=1  姓名=张  性别=M  成绩=76
以p-<输出:
学号=1  姓名=张  性别=M  成绩=76

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

  总结:

这个程序还可以,就是一个固定输出。没有出现问题。

 

例题作业

标签:after   second   ted   proc   arp   难度   知识点   return   ++   

原文地址:http://www.cnblogs.com/qq1647367415/p/6691138.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!