当前位置: 首页 > news >正文

C++练习1

#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) * (%d+%di) = %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 res;res.real=x.real*y.real-x.imag*y.imag;res.imag=x.real*y.imag+x.imag*y.real;return res;
}
#include <stdio.h>
#include <math.h>struct point {double x, y, z;
};void read_point(struct point *p);
double distance(struct point a, struct point b);int main(void)
{struct point p1, p2;read_point(&p1);read_point(&p2);printf("%f\n", distance(p1, p2));return 0;
}void read_point(struct point *p)
{scanf("%lf %lf %lf", &p->x, &p->y, &p->z);
}//  计算并返回平面上两点 a 和 b 之间的欧氏距离
double distance(struct point a, struct point b){double res;res=pow((a.x-b.x),2)+pow((a.y-b.y),2)+pow((a.z-b.z),2);res=sqrt(res);return res;
}

 

http://icebutterfly214.com/news/10826/

相关文章:

  • 第二届数证杯初赛-计算机取证
  • puty总是自动断开连接,修改配置即可
  • 题解:CF1037E Trips
  • 2025 CSP-S 游记
  • java 基础语法一
  • CSP-S游记
  • csp2025 总结
  • 使用Stream API重构你的数据处理
  • 一个灵感:思维的断章
  • 通达信:引用函数 - Leone
  • 20231427田泽航第七周预习报告
  • Awesome Neovim - 精选Neovim插件大全
  • 游记 CSP-S2025
  • 解码LVGL样式
  • Edge---浏览器优化配置
  • 打造你自己的 Linux 备份命令:快速、高效、易用 【from claude.ai Haiku 4.5】
  • pdf下载网站
  • 2025 年 11 月氨糖软骨素厂家哪家好?剂型优化与人群适配双维度测评推荐
  • range()
  • 2025 年 11 月氨糖软骨素厂家哪家好?提纯工艺与长效养护双核心测评推荐
  • 基于嵌入式无人机UAV通信系统的实时最优资源分配算法matlab仿真
  • 构建现代Web应用:使用React框架打造单页面应用
  • 完全背包内外循环是否能对调?
  • 《密码系统设计》第九周预习
  • 回归 CSP-S2025游记
  • 有哪些好用的媒体播放器
  • THUSC 2024 游记
  • 2025年10月学习机品牌推荐:护眼大屏榜对比与品牌排名
  • 2025年11月福田欧曼重卡销量靠谱榜:生产厂家排名与全品系销量评测
  • 2025年福田欧曼重卡深度解析:权威推荐全场景价值标杆