c語言輸出復數
⑴ 怎樣用c語言輸入或者輸出一個復數詳細講解一下喲.
C語言本身沒有復數這個數據類型,但是你可以自己定義:
typedef struct
{
double real; /* 實部 */
double imag; /* 虛部 */
}ComplexNumber;
然後你可以使用ComplexNumber來定義變數,然後用scanf("%f,%f", &cn.real, &cn.imag);這樣的語句來輸入復數,還可以進行其它任意操作。
⑵ C語言 復數表示與求和
在數學中一個復數可以定義為 (z=a + bi) 的形式。 C 語言在 ISO C99 時就引入了復數類型。它是通過 complex.h 中定義的。 我們可以使用 complex , __complex__ , 或 _ComplexI 類型符號來表示。
在C語言中有三種復數類型,分別為 float complex , double complex , long double complex 。他們之間 的區別就是表示復數中實部和虛步的數的數據類型不同。 complex 其實就是一個數組,數組中有兩個元素,一個表示復數的實部,一個表示復數的虛部。
源代碼如下:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
double sum(double* x);
void main()
{
double *a,s=0.0;
a=(double*)malloc(sizeof(double));
*a=5;
s=sum(a);
printf("求和的結果是: %lf ",s);
}double sum(double* x)
{
int j=0;
double s=0.0;
for(j=0;j<=3;j++)
{
s=s+pow(*x,j);
}
s=s*2;
return s;
}
(2)c語言輸出復數擴展閱讀
輸入任意兩個復數差與商的源代碼如下
typedefstruct{
floatr;
floatim;
Complex;
Complexres;
Complex*add(Complex*a,Complex*b){
res.r=a->r+b->r;
res.im=a->im+b->im;
return&res;
}
Complex*div(Complex*a,Complex*b){
floatd=(b->r*b->r+b->im*b->im);
res.r=(a->r*b->r+a->im*b->im)/d;
res.im=(a->im*b->r-a->r*b->im)/d;
return&res;
⑶ 數據結構c語言復數運算
1、首先打開vc6.0, 新建一個項目。