当前位置:网站首页>How to use C language code to realize the addition and subtraction of complex numbers and output structure
How to use C language code to realize the addition and subtraction of complex numbers and output structure
2022-07-04 07:46:00 【Yisu cloud】
How to use it? C The language code realizes the addition and subtraction of complex numbers and the output structure
This article “ How to use it? C The language code realizes the addition and subtraction of complex numbers and the output structure ” Most people don't quite understand the knowledge points of the article , So I made up the following summary for you , Detailed content , The steps are clear , It has certain reference value , I hope you can gain something after reading this article , Let's take a look at this article “ How to use it? C The language code realizes the addition and subtraction of complex numbers and the output structure ” Article bar .
One 、 Addition and subtraction of complex numbers
#include<stdio.h> typedef struct complex { int real; // Real component int imag; // Imaginary part }complex; /* function : Plural addition Parameters : Two plurals Return value : The sum of two plural numbers */ complex complexadd(complex x,complex y) { complex sum; sum.real = x.real + y.real; sum.imag = x.imag + y.imag; return sum; } /* function : Complex subtraction Parameters : Two plurals Return value : The difference between two complex numbers */ complex complexsub(complex x,complex y) { complex sum; sum.real = x.real - y.real; sum.imag = x.imag - y.imag; return sum; } /* function : Print plurals Parameters : A plural */ void printfcomplex(complex x) { printf("%d",x.real); if(x.imag > 0) { printf("+"); } printf("%d\n",x.imag); } int main() { complex f1 = {3,-5}; complex f2 = {-5,8}; printfcomplex(f1); printfcomplex(f2); complex f3 = complexadd(f1,f2); printfcomplex(complexadd(f1,f2)); printfcomplex(f3); printfcomplex(complexsub(f1,f2)); return 0; }
Two 、 Sub documents complex.c
#include<stdio.h> #include"complex.h" /* function : Plural addition Parameters : Two plurals Return value : The sum of two plural numbers */ complex complexadd(complex x,complex y) { complex sum; sum.real = x.real + y.real; sum.imag = x.imag + y.imag; return sum; } /* function : Complex subtraction Parameters : Two plurals Return value : The difference between two complex numbers */ complex complexsub(complex x,complex y) { complex sum; sum.real = x.real - y.real; sum.imag = x.imag - y.imag; return sum; } /* function : Print plurals Parameters : A plural */ void printfcomplex(complex x) { printf("%d",x.real); if(x.imag > 0) { printf("+"); } printf("%di\n",x.imag); }
main.c
#include<stdio.h> #include"complex.h" // complex The header file int main() { complex f1 = {3,-5}; // Structure initialization complex f2 = {-5,8}; printfcomplex(f1); // Print plurals printfcomplex(f2); complex f3 = complexadd(f1,f2); printfcomplex(complexadd(f1,f2)); printfcomplex(f3); printfcomplex(complexsub(f1,f2)); return 0; }
complex.h
#ifndef __COMPLEX_H__ #define __COMPLEX_H__ // Type declaration typedef struct complex { int real; // Real component int imag; // Imaginary part }complex; /* function : Plural addition Parameters : Two plurals Return value : The sum of two plural numbers */ complex complexadd(complex x,complex y); /* function : Complex subtraction Parameters : Two plurals Return value : The difference between two complex numbers */ complex complexsub(complex x,complex y); /* function : Print plurals Parameters : A plural */ void printfcomplex(complex x); #endif
That's about “ How to use it? C The language code realizes the addition and subtraction of complex numbers and the output structure ” The content of this article , I believe we all have a certain understanding , I hope the content shared by Xiaobian will be helpful to you , If you want to know more about it , Please pay attention to the Yisu cloud industry information channel .
边栏推荐
- 【Go基础】2 - Go基本语句
- 墨者学院-Webmin未经身份验证的远程代码执行
- Take you to master the formatter of visual studio code
- 神经网络入门(下)
- [test de performance] lire jmeter
- [Gurobi] 简单模型的建立
- I was pressed for the draft, so let's talk about how long links can be as efficient as short links in the development of mobile terminals
- Xcode 14之大变化详细介绍
- 时序数据库 InfluxDB 2.2 初探
- Scanf read in data type symbol table
猜你喜欢
Text processing function sorting in mysql, quick search of collection
Node foundation ~ node operation
Zephyr study notes 2, scheduling
[network security] what is emergency response? What indicators should you pay attention to in emergency response?
How to use MOS tube to realize the anti reverse connection circuit of power supply
window上用.bat文件启动项目
Zephyr learning notes 1, threads
Tri des fonctions de traitement de texte dans MySQL, recherche rapide préférée
Wechat has new functions, and the test is started again
zabbix監控系統自定義監控內容
随机推荐
The text box displays the word (prompt text) by default, and the text disappears after clicking.
21 examples of strategic goals to promote the rapid development of your company
When JDBC connects to es query, is there a God who meets the following situation?
PCIE知识点-010:PCIE 热插拔资料从哪获取
The frost peel off the purple dragon scale, and the xiariba people will talk about database SQL optimization and the principle of indexing (primary / secondary / clustered / non clustered)
Zephyr 学习笔记1,threads
zabbix监控系统自定义监控内容
System architecture design of circle of friends
Leetcode 23. Merge K ascending linked lists
Docker install MySQL
L2-013 red alarm (C language) and relevant knowledge of parallel search
运动【跑步 01】一个程序员的半马挑战:跑前准备+跑中调整+跑后恢复(经验分享)
Zephyr 学习笔记2,Scheduling
Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
What are the work contents of operation and maintenance engineers? Can you list it in detail?
Using the rate package for data mining
手写简易版flexible.js以及源码分析
Oracle-存储过程与函数
JVM -- class loading process and runtime data area
1、卡尔曼滤波-最佳的线性滤波器