亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C語言復數(shù)的加減及輸出結(jié)構(gòu)體

 更新時間:2022年02月11日 15:06:01   作者:Joyce--  
大家好,本篇文章主要講的是C語言復數(shù)的加減及輸出結(jié)構(gòu)體,感興趣的同學趕快來看一看吧,對你有幫助的話記得收藏一下

    一、

#include<stdio.h>
 
typedef struct complex
{
	int real;	//實部
	int imag;	//虛部
}complex;
 
/*
	功能:復數(shù)加法
	參數(shù):兩個復數(shù)
	返回值:兩個復數(shù)的和
*/
complex complexadd(complex x,complex y)
{
	complex sum;
	sum.real = x.real + y.real;
	sum.imag = x.imag + y.imag;
	return sum;
}
 
/*
	功能:復數(shù)減法
	參數(shù):兩個復數(shù)
	返回值:兩個復數(shù)的差
*/
complex complexsub(complex x,complex y)
{
	complex sum;
	sum.real = x.real - y.real;
	sum.imag = x.imag - y.imag;
	return sum;
}
 
/*
	功能:打印復數(shù)
	參數(shù):一個復數(shù)
*/
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;
}
 
 

二、分文件

complex.c

#include<stdio.h>
#include"complex.h"
 
 
/*
	功能:復數(shù)加法
	參數(shù):兩個復數(shù)
	返回值:兩個復數(shù)的和
*/
complex complexadd(complex x,complex y)
{
	complex sum;
	sum.real = x.real + y.real;
	sum.imag = x.imag + y.imag;
	return sum;
}
 
/*
	功能:復數(shù)減法
	參數(shù):兩個復數(shù)
	返回值:兩個復數(shù)的差
*/
complex complexsub(complex x,complex y)
{
	complex sum;
	sum.real = x.real - y.real;
	sum.imag = x.imag - y.imag;
	return sum;
}
 
/*
	功能:打印復數(shù)
	參數(shù):一個復數(shù)
*/
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 頭文件
 
int main()
{	
	complex f1 = {3,-5};		// 結(jié)構(gòu)體初始化
	complex f2 = {-5,8};
	printfcomplex(f1);			// 打印復數(shù)
	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__
 
// 類型聲明
typedef struct complex
{
	int real;	//實部
	int imag;	//虛部
}complex;
 
/*
	功能:復數(shù)加法
	參數(shù):兩個復數(shù)
	返回值:兩個復數(shù)的和
*/
complex complexadd(complex x,complex y);
 
/*
	功能:復數(shù)減法
	參數(shù):兩個復數(shù)
	返回值:兩個復數(shù)的差
*/
complex complexsub(complex x,complex y);
 
 
/*
	功能:打印復數(shù)
	參數(shù):一個復數(shù)
*/
void printfcomplex(complex x);
 
 
#endif

到此這篇關(guān)于C語言復數(shù)的加減及輸出結(jié)構(gòu)體的文章就介紹到這了,更多相關(guān)C語言復數(shù)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • C語言俄羅斯方塊游戲課程設計

    C語言俄羅斯方塊游戲課程設計

    這篇文章主要為大家詳細介紹了C語言俄羅斯方塊游戲課程設計,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-06-06
  • 快速入門的一些C\C++書籍

    快速入門的一些C\C++書籍

    這篇文章為大家精心推薦了一些快速入門的一些C\C++書籍,希望大家可以喜歡,對這門語言可以產(chǎn)生興趣,需要的朋友可以參考下
    2015-12-12
  • 詳解C++如何實現(xiàn)在Word文檔中創(chuàng)建列表

    詳解C++如何實現(xiàn)在Word文檔中創(chuàng)建列表

    這篇文章主要為大家詳細介紹了介紹如何使用C++在Word文檔中創(chuàng)建編號列表、項目符號列表和多級列表,感興趣的小伙伴可以跟隨小編一起學習一下
    2023-05-05
  • 用C/C++代碼檢測ip能否ping通(配合awk和system可以做到批量檢測)

    用C/C++代碼檢測ip能否ping通(配合awk和system可以做到批量檢測)

    今天小編就為大家分享一篇關(guān)于用C/C++代碼檢測ip能否ping通(配合awk和system可以做到批量檢測),小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-04-04
  • C++實現(xiàn)猜數(shù)字游戲

    C++實現(xiàn)猜數(shù)字游戲

    這篇文章主要為大家詳細介紹了C++實現(xiàn)猜數(shù)字游戲,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-07-07
  • 深入解析int(*p)[]和int(**p)[]

    深入解析int(*p)[]和int(**p)[]

    以下是對int(*p)[]和int(**p)[]的使用進行了詳細的分析介紹,需要的朋友可以參考下
    2013-07-07
  • 如何在C語言中判斷socket是否已經(jīng)斷開

    如何在C語言中判斷socket是否已經(jīng)斷開

    如果不主動關(guān)閉socket的話,系統(tǒng)不會自動關(guān)閉的,除非當前進程掛掉了,操作系統(tǒng)把占用的socket回收了才會關(guān)閉。小編今天跟大家簡單介紹下如何在C語言中判斷socket是否已經(jīng)斷開
    2019-05-05
  • AVX2指令集優(yōu)化整形數(shù)組求和算法

    AVX2指令集優(yōu)化整形數(shù)組求和算法

    這篇文章主要為大家介紹了AVX2指令集優(yōu)化整形數(shù)組求和算法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-05-05
  • c語言單詞搜索的實現(xiàn)

    c語言單詞搜索的實現(xiàn)

    本文主要介紹了c語言單詞搜索的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-04-04
  • 詳細分析C++ 數(shù)據(jù)封裝和數(shù)據(jù)抽象

    詳細分析C++ 數(shù)據(jù)封裝和數(shù)據(jù)抽象

    這篇文章主要介紹了C++ 數(shù)據(jù)封裝和數(shù)據(jù)抽象的的相關(guān)資料,文中代碼非常詳細,幫助大家更好的理解和學習,感興趣的朋友可以了解下
    2020-06-06

最新評論