zoukankan      html  css  js  c++  java
  • 第三次作业

    作业要求一 
    1 完成
    2  struct sk{int a; char *str)}*p;   p->str++ 中的++ 加向str字符串中的字符++。

    作业要求二

    请将pta作业编程题目的1和2解题思路和调试过程记录在博客中,每道题目的具体格式如下:

    题目1.查找书籍中最高价及最低价

    设计思路:

    (1)需要比较不同的书名和价格,建立book结构体

    (2) 把最大值max和最小值min,赋予初值

    (3)在for循环中进行比较,找到最高值或者最低值,输出

    代码

    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    struct book
    {
      char name[31];
      double cost;
    };
    main()
    {
      struct book s[10];
      int i,n;
      scanf("%d",&n);
      for(i=0;i<n;i++)
      { 
        scanf("
    ");
         gets(s[i].name); 
         scanf("%lf",&s[i].cost);  
      }
      int max=0,min=0;
      for(i=1;i<n;i++)
       {
         if(s[i].cost>s[max].cost){max=i;}
         if(s[i].cost<s[min].cost){min=i;}
       }
       printf("%.2f, %s
    ",s[max].cost,s[max].name);
       printf("%.2f, %s",s[min].cost,s[min].name);
       
    }

    错误以及解决方法:

    本题无错误

    题目2 计算平均成绩

    设计思路:

    (1)建立结构体

    (2)赋初值,并输入同学的个数以及对应的学号,姓名,成绩,并把学生的成绩进行累加

    (3)进行计算输出低于平均成绩同学的姓名与成绩

    代码:

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    struct student
    {
        char num[20];
        char name[20];
        double s;
     };
    int main()
     {
         struct student s[1000];
         int i,n;
         double aver=0;
         scanf("%d",&n);
         for(i=0;i<n;i++)
         {
             scanf("%s %s %lf",&s[i].num,&s[i].name,&s[i].s);
         }
         for(i=0;i<n;i++)
         {
             aver= aver + s[i].s;
         }
         aver=aver/n;
         printf("%.2f
    ",aver);
         for(i=0;i<n;i++)
         {
             if(s[i].s<aver)
             {
             printf("%s %s
    ",s[i].name,s[i].num);
         }
    }
         return 0;
     }

    错误以及解决方法:

    1.忘记一些符号:仔细观察发现错误


    要求三、学习总结和进度
    1、
    2、git截图

    git地址:

    https://git.coding.net/shupeng521/asd.git

  • 相关阅读:
    《火影忍者:究级风暴》渲染技术究极解析!
    动态数组和内置数组转换范例
    固定视角
    旋转
    时间间隔操作
    编辑器的一些批处理脚本
    访问GUItexture
    血槽制作
    动画循环播放
    软件测试修炼之道之——重现问题(上)
  • 原文地址:https://www.cnblogs.com/shupeng521/p/8909507.html
Copyright © 2011-2022 走看看