当前位置:网站首页>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 .
边栏推荐
- Thesis learning -- time series similarity query method based on extreme point characteristics
- Blog stop statement
- In the era of low code development, is it still needed?
- Routing decorator of tornado project
- 2022-021ARTS:下半年開始
- zabbix监控系统部署
- With excellent strength, wangchain technology, together with IBM and Huawei, has entered the annual contribution list of "super ledger"!
- ZABBIX monitoring system deployment
- 21 examples of strategic goals to promote the rapid development of your company
- Rapidjson reading and writing JSON files
猜你喜欢
Chrome is set to pure black
Devops Practice Guide - reading notes (long text alarm)
Oracle-存储过程与函数
L2-013 red alarm (C language) and relevant knowledge of parallel search
Google's official response: we have not given up tensorflow and will develop side by side with Jax in the future
The idea of implementing charts chart view in all swiftui versions (1.0-4.0) was born
在所有SwiftUI版本(1.0-4.0)中原生实现Charts图表视图之思路
Preliminary study on temporal database incluxdb 2.2
论文学习——基于极值点特征的时间序列相似性查询方法
Practice (9-12 Lectures)
随机推荐
Figure guessing game
OKR vs. KPI 一次搞清楚这两大概念!
What determines vacuum permittivity and vacuum permeability? Why do these two physical quantities exist?
博客停更声明
2022 - 021arts: début du deuxième semestre
如何用MOS管来实现电源防反接电路
Relations courantes de la fiche de données d'exploitation pour les activités
Mysql database - function constraint multi table query transaction
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-...)
运动【跑步 01】一个程序员的半马挑战:跑前准备+跑中调整+跑后恢复(经验分享)
Guoguo took you to write a linked list, and the primary school students said it was good after reading it
Take you to master the formatter of visual studio code
Basic DOS commands
墨者学院-PHPMailer远程命令执行漏洞溯源
Scanf read in data type symbol table
[network security] what is emergency response? What indicators should you pay attention to in emergency response?
L1-028 judging prime number (10 points)
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)
Unity-写入Word
What are the work contents of operation and maintenance engineers? Can you list it in detail?