07.21C_struct

【项目1-复数结构体】编写一个程序,首先定义一个复数数据类型,即结构类型。然后按照复数的运算规则进行计算,并按照复数表示的格式进行输出,请将程序补充完整。【项目2-学生成绩处理】(1)定义学生结构体,在结构体数组中,输入了学生学号和两门课的成绩,计算均分后,输出成绩单,请在下面的程序基础上,将程序补充完整。 (2)请在上面的程序的基础上增加功能,使运行结果如
摘要由CSDN通过智能技术生成

【项目1-复数结构体】

编写一个程序,首先定义一个复数数据类型,即结构类型。然后按照复数的运算规则进行计算,并按照复数表示的格式进行输出,请将程序补充完整。

解法:
#include <stdio.h>
#include <stdlib.h>

int main()
{
    typedef struct
    {
        double real;
        double imag;

    }complex_n;
    complex_n com1,com2,com3;
    printf("please enter the real part and imagine part of the two complex number:");
    scanf("%lf%lf%lf%lf",&com1.real,&com1.imag,&com2.real,&com2.imag);
    com3.real=com1.real*com2.real-com1.imag*com2.imag;
    com3.imag=com1.real*com2.imag+com1.imag*com2.real;
    printf("the result is %.2lf+%.2lfi",com3.real,com3.imag);
    return 0;
}

【项目2-学生成绩处理】

(1)定义学生结构体,在结构体数组中,输入了学生学号和两门课的成绩,计算均分后,输出成绩单,请在下面的程序基础上,将程序补充完整。 
这里写图片描述

解法:
#include <stdio.h>
#include <stdlib.h>
#define N 100

struct student
{
    int num;
    int score_c;
    int score_math;
    double aver;
};
int main()
{
    int n;
    int i;
    int pass=0;
    struct student stu[N];
    printf("please enter the amount of the student:");
    scanf("%d",&n);
    fflush(stdin);
    for(i=0;i<n;++i)
    {
    printf("please enter the number score of c and math of the %d-th student:\n",i);
    scanf("%d%d%d",&((stu+i)->num),&((stu+i)->score_c),&((stu+i)->score_math));
    (stu+i)->aver=((stu+i)->score_c+(stu+i)->score_math)/2;
    if((stu+i)->score_c<60&&(stu+i)->score_math<60)
        ++pass;
    }
    printf("score report\n");
    fflush(stdin);
    printf("number\tc\tmath\taverage\t\n");
    for(i=0;i<n;++i)
    {
        printf("%d\t%d\t%d\t%.2lf\t",(stu+i)->num,(stu+i)->score_c,(stu+i)->score_math,(stu+i)->aver);
        printf("\n");
    }
    printf("the amount of the students did not pass:%d",pass);
    return 0;
}
【项目3-点结构体】
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值