当前位置:网站首页>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 .
边栏推荐
- Système de surveillance zabbix contenu de surveillance personnalisé
- Take you to master the formatter of visual studio code
- Life planning (flag)
- [Chongqing Guangdong education] National Open University spring 2019 770 real estate appraisal reference questions
- 神经网络入门(下)
- Thesis learning -- time series similarity query method based on extreme point characteristics
- 手写简易版flexible.js以及源码分析
- How to reset IntelliSense in vs Code- How to reset intellisense in VS Code?
- Amd RX 7000 Series graphics card product line exposure: two generations of core and process mix and match
- [gurobi] establishment of simple model
猜你喜欢
socket inet_ pton() inet_ Ntop() function (a new network address translation function, which converts the expression format and numerical format to each other. The old ones are inet_aton(), INET_ ntoa
Unity 从Inspector界面打开资源管理器选择并记录文件路径
Easy to understand: understand the time series database incluxdb
zabbix监控系统邮件报警配置
论文学习——基于极值点特征的时间序列相似性查询方法
神经网络入门(下)
Distributed transaction management DTM: the little helper behind "buy buy buy"
User login function: simple but difficult
Sqli labs download, installation and reset of SQL injection test tool one of the solutions to the database error (# 0{main}throw in d:\software\phpstudy_pro\www\sqli labs-...)
BUUCTF(3)
随机推荐
L1-024 the day after tomorrow (5 points)
BUUCTF(4)
Literature collation and thesis reading methods
System architecture design of circle of friends
Go h*ck yourself:online reconnaissance (online reconnaissance)
【Go基础】1 - Go Go Go
Guoguo took you to write a linked list, and the primary school students said it was good after reading it
[test de performance] lire jmeter
[network security] what is emergency response? What indicators should you pay attention to in emergency response?
ZABBIX monitoring system deployment
One of the general document service practice series
Node foundation ~ node operation
Oracle stored procedures and functions
rapidjson读写json文件
博客停更声明
[web security] nodejs prototype chain pollution analysis
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)
BUUCTF(3)
Google's official response: we have not given up tensorflow and will develop side by side with Jax in the future
Sqli labs download, installation and reset of SQL injection test tool one of the solutions to the database error (# 0{main}throw in d:\software\phpstudy_pro\www\sqli labs-...)