C语言程序设计报告第九章

#include<stdio.h>

struct ser

{

    int h,m,s;

} time;

int main()

{

    int x;

    scanf("%d:%d:%d",&time.h,&time.m,&time.s);

    scanf("%d",&x);

    time.s+=x;

    if(time.s>=60)

    {

        time.m+=1;

        time.s=time.s-60;

        if(time.m>=60)

        {

            time.h+=1;

            time.m=time.m-60;

            if(time.h==24)

            {

                time.h=0;

            }

        }

    }

    printf("%d :%d :%d\n",time.h,time.m,time.s);

    return 0;

}

#include<stdio.h>

struct ser

{

    int n;

    char a[20];

    double m;

}q[10];

int main()

{

    int x;

    scanf("%d",&x);

    for(int i=0;i<x;i++)

    scanf("%d %s %lf",&q[i].n,q[i].a,&q[i].m);

    double sum=0;

    for(int i=0;i<x;i++)

    {

        sum=sum+q[i].m;

    }

    printf("%.2lf",sum/x);

    return 0;

}

#include <stdio.h>

struct complex{

    int real;

    int imag;

};

struct complex multiply(struct complex x, struct complex y);

int main()

{

    struct complex product, x, y;

    scanf("%d%d%d%d", &x.real, &x.imag, &y.real, &y.imag);

    product = multiply(x, y);

    printf("(%d+%di)\n(%d+%di)\n%d+%di\n",

            x.real, x.imag, y.real, y.imag, product.real, product.imag);

    return 0;

}
struct complex multiply(struct complex x, struct complex y){

struct complex z;

z.real = x.real * y.real - x.imag * y.imag;

z.imag = x.real * y.imag + x.imag * y.real;

return z;
}
#include<stdio.h>

struct book

{

    char name[10];

    float price;

};

int main()

{

    struct book a[10];

    int min=0,max=0,n,i;

    scanf("%d",&n);

    for(i=1; i<=n; i++)

    {

        scanf("%s%f",a[i-1].name,&a[i-1].price);

    }

    for(i=1; i<n; i++)

    {

        if(a[i].price>a[max].price)

            max=i;

        if(a[i].price<a[min].price)

            min=i;

 

    }

    printf("%.1f,%s\n",a[max].price,a[max].name);

    printf("%.1f,%s\n",a[min].price,a[min].name);

    return 0;

}

#include<stdio.h>

struct student

{

    int n;

    char a[20];

    double m;

}q[10];

int set_grade(double x)

{

    if(x<=59)

    {

        return 'D';

    }

    else if(x<=69)

    {

        return 'C';

    }

    else if(x<=84)

    {

        return 'B';

    }

    else

    {

        return 'A';

    }

}

int main ()

{

    for(int i=0;i<10;i++)

    {

        scanf("%d %s %lf",&q[i].n,q[i].a,&q[i].m);

    }

    for(int i=0;i<10;i++)

    {

        char str=set_grade(q[i].m);

        printf("%d %s %lf %c\n",q[i].n,q[i].a,q[i].m,str);

    }

    return 0;

}

/*

1 asd 85

2 wer 75

3 wrt 70

4 bgu 84

5 tyi 90

6 gut 69

7 ghb 60

8 yut 50

9 guy 100

10 edc 78

*/

三、改错

#include<stdio.h>

int main()

{

    char str[]="总分最高的学生是:",s[]="分";//存入一个字符型汉字数组

    struct students

    {

        int number;

        char name[20];

        int score[3];

        int sum;

    }student[100];//student[100]定义一个结构体数组

    int i,j,k,n,max=0;

    printf("n=");

    scanf("%d",&n);

    for(i=0; i<n; i++)

    {

        scanf("%d%s",&student[i].number,student[i].name);

        for(j=0; j<3; j++)

        {

            scanf("%d",&student[i].score[j]);

        }

        student[i].sum=student[i].score[0]+student[i].score[1]+student[i].score[2];

    }

    k=0;

    max=student[0].sum;

    for(i=0; i<n; i++)

    {

        if(max<student[i].sum)

        {

            max=student[i].sum;//更新max的值

            k=i;

        }

 

    }

 

    printf("%s %s, %d%s\n",str,student[k].name,student[k].sum,s);//变成输出汉字型

    return 0;

}

/*

5

1 wer 23 44 67

2 rer 34 67 88

3 rdf 65 76 44

4 fgh 99 99 99

5 fby 56 88 54

5

1 黄岚 78 83 75

2 王海 76 80 77

3 沈强 87 85 76

4 张枫 92 88 78

5 章盟 80 82 75

*/

(1)

#include<stdio.h>

#include<iostream>

#include<algorithm>

using namespace std;

struct date

{

    int a;

    int b;

    int c;

};

struct node

{

    char name[20];

    struct date birth;

    char num[50];

} node[100],t;

int n;

void sort()

{

    int i,j;

    for(i=0; i<n; i++)

    {

        for(j=0; j<n-i-1; j++)

        {

            if(node[j].birth.a<node[j+1].birth.a)

            {

                t=node[j];

                node[j]=node[j+1];

                node[j+1]=t;

            }

        }

    }

    for(i=0; i<n; i++)

    {

        printf("%s ",node[i].name);

        printf("%d ",node[i].birth.a);

        printf("%s\n",node[i].num);

    }

}

int main()

{

    int i;

    cin>>n;

    for(i=0; i<n; i++)

    {

        scanf("%s",node[i].name);

        scanf("%d %d %d",&node[i].birth.a,&node[i].birth.b,&node[i].birth.c);

        node[i].birth.a=((node[i].birth.a*100+node[i].birth.b)*100+node[i].birth.c);

        scanf("%s",node[i].num);

    }

    sort();

    return 0;

}

/*

3

zhang 1985 04 03 13912345678

wang 1982 10 20 86057188018448

qian 1984 06 19 13609876543

*/

(2)

#include<stdio.h>

int main()

{

    int compareRational(double x,double y);

    double x,y,a,b,c,d;

    int r=0;

    scanf("%lf/%lf",&a,&b);

    x=a/b;

    scanf("%lf/%lf",&c,&d);

    y=c/d;

    r=compareRational(x,y);

    if(r==-1)

    {

        printf("%.lf / %.lf < %.lf / %.lf\n",a,b,c,d);

    }

    else if(r==0)

    {

        printf("%.lf / %.lf = %.lf / %.lf\n",a,b,c,d);

    }

    else

    {

        printf("%.lf / %.lf > %.lf / %.lf\n",a,b,c,d);

    }

    //printf("%d\n",r);

    return 0;

}

int compareRational(double x,double y)

{

    if (x>y)

        return 1;

    else if (x<y)

        return -1;

    else

        return 0;

}

/*

1/2 3/4

*/

(3)

#include<stdio.h>

#include<math.h>

//#include<stdlib.h>

#include<string.h>

int main()

{

    struct vec

    {

        double x;

        double y;

    } v1, v2;

    scanf("%lf %lf %lf %lf", &v1.x, &v1.y, &v2.x, &v2.y);

    double a, b;

    a = v1.x+v2.x;

    b = v1.y+v2.y;

    if(a < 0 && a > -0.05)

        a = 0.0;

    if(b < 0 && b > -0.05)

        b = 0.0;

    printf("(%.1f, %.1f)", a, b);

}

/*

3.5 -2.7 -13.9 8.7

*/

阅读更多

没有更多推荐了,返回首页