栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

Python123第九章答案

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python123第九章答案

Python123第九章答案(自写,仅供参考) By:肇院伟烨

前言 1、代码自己写的,不是标准答案,仅供参考。 2、建议看懂后自己另外写而不是复制粘贴。 3、点击目录可以转跳

文章目录
    • 前言
    • 1、代码自己写的,不是标准答案,仅供参考。
    • 2、建议看懂后自己另外写而不是复制粘贴。
    • 3、点击目录可以转跳
  • 第九章
    • 第1题
    • 第2题
    • 第3题
    • 第4题
    • 第5题
    • 第6题

第九章 第1题
#include 

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) * (%d+%di) = %d + %din",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 result;
	result.real=x.real*y.real-x.imag*y.imag;
	result.imag=x.real*y.imag+x.imag*y.real;
	return result;
} 

第2题
#include 
#define MAXN 10
struct student{
    int num;
    char name[20];
    int score;
    char grade;
}
;
int set_grade( struct student *p, int n );
int main()
{
    struct student stu[MAXN], *ptr;
    int n, i, count;
    ptr = stu;
    scanf("%dn", &n);
    for(i = 0;i < n;i++)
    {
        scanf("%d%s%d", &stu[i].num, stu[i].name, &stu[i].score);
    }
    count = set_grade(ptr, n);
    printf("The count for failed (<60): %dn", count);
    printf("The grades:n");
    for(i = 0;i < n;i++)
    printf("%d %s %cn", stu[i].num, stu[i].name, stu[i].grade);
    return 0;
}
int set_grade( struct student *p, int n )
{
    int i,count=0;
    for(i=0;i=70)
        p[i].grade='B';
        else if(p[i].score>=60)
        p[i].grade='C';
        else
        {
            p[i].grade='D';
            count++;
        }
    }
    return count;
}

第3题
#include 
struct Time
{
	int hour;
	int minute;
	int second;
};
int main()
{
	struct Time time;
	int addtime;
	scanf("%d:%d:%d", &time.hour, &time.minute, &time.second);
	scanf("%d", &addtime);
	if (time.second + addtime >= 60)
	{
		time.second = time.second + addtime - 60;
		time.minute++;
	}
	else
	{
		time.second += addtime;
	}
	if (time.minute>= 60)
	{
		time.minute = time.minute - 60;
		time.hour++;
	}
	if (time.hour >= 24)
	{
		time.hour = 0;
	}
	printf("%02d:%02d:%02d", time.hour, time.minute, time.second);
	return 0;
}
第4题
#include
struct vector {
    double x;
    double y;
};
int main()
{
    struct vector v1, v2, v;
    scanf("%lf%lf%lf%lf", &v1.x, &v1.y, &v2.x, &v2.y);
    v.x = v1.x + v2.x;
    v.y = v1.y + v2.y;
    printf("(%.1lf, %.1lf)", v.x, v.y);
    return 0;
}
第5题
#include
struct BOOK {
    char name[30];
    double price;
};
int main()
{
    struct BOOK book[10];
    int n, i;
    int e_index,c_index;
    scanf("%d", &n);
    getchar();
    for(i=0;i book[e_index].price)
            e_index = i;
        if (book[i].price < book[c_index].price)
            c_index = i;
    }
    printf("%.2lf, %sn", book[e_index].price, book[e_index].name);
    printf("%.2lf, %s", book[c_index].price, book[c_index].name);
    return 0;
}
第6题
#include
struct Contact {
    char name[10];
    int birthday;
    char phone[17];
};
int main()
{
    struct Contact contact[10],temp;
    int n, i, j;
    scanf("%d", &n);
    for(i=0;i contact[i + 1].birthday)
            {
                temp = contact[i];
                contact[i] = contact[i+1];
                contact[i+1]= temp;
            }
    for (i = 0; i < n; i++)
    {
        printf("%s %d %sn", contact[i].name,contact[i].birthday,contact[i].phone);
    }
    return 0;
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/690390.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号