① c語言定義復數
#include <complex>
#include <iostream>
using namespace std;void main()
{
complex<double> comp(1,1); cout << "The complex number = " << comp << endl; cout<<"real:"<<comp.real()<<endl;
cout<<"image:"<<comp.imag()<<endl; comp=conj(comp);
cout << "The complex number = " << comp << endl;
cout<<"real:"<<comp.real()<<endl;
cout<<"image:"<<comp.imag()<<endl;
}
② 在c語言里,復數和虛數類型代表著什麼意思該怎麼用
對C語言本身沒什麼意義,C語言沒有內置的向量。但你在處理圖形或其他帶有矢量計算的地方就需要使用復數,比如:做力學的模擬實驗時進行力的合成等等,將某個圖片進行旋轉。
③ 怎樣用C語言輸入或者輸出一個復數詳細講解一下喲.
C語言本身沒有復數這個數據類型,但是你可以自己定義:
typedef struct
{
double real; /* 實部 */
double imag; /* 虛部 */
}ComplexNumber;
然後你可以使用ComplexNumber來定義變數,然後用scanf("%f,%f", &cn.real, &cn.imag);這樣的語句來輸入復數,還可以進行其它任意操作。
④ C語言(有關復數)
你在VC中得不到正確的結果是因為printf函數的描述符用錯了,把%d改為%f
在TC中編譯錯誤是因為TC比VC檢查要嚴格,是一個標準的C編譯器,而VC其實是一個VC++編譯器
在TC中聲明了結構之後定義結構變數不能省略struct關鍵字,如要省略,則必須給該結構類型起個別名。對於你的程序來說,只要把復數類型聲明改為如下方式即可,你試試吧:
typedef struct {
double real;
double imag;
} complex;
⑤ -complex在C語言中是什麼意思呀!
-complex在C語言中是用來表示復數。
C99標准中定義的復數類型如下:float_Complex; float_Imaginary; double_Complex; double_Imaginary; long double_Complex; long double_Imaginary.
頭文件中定義了complex和imaginary宏,並將它們擴展為_Complex和_Imaginary,因此在編寫新的應用程序時,應該使用頭文件中的complex和imaginary宏。
(5)c語言中的復數是什麼擴展閱讀
complex的使用:
float_ Complex;
float_ Imaginary;
double_ .Complex ;
double_ Imaginary;
long double_ Complex;
long double_ Imaginary.
⑥ c語言什麼是復數和虛數
虛數和復數,是數學上的概念。
詳見:網路「虛數」和「復數」。
⑦ C語言中怎麼進行復數的定義及運算
定義成結構體 實部和虛部分別定義成double,然後在自己定義運算……
如果是C++的話,可以重載+、-、*、\操作符的方式
⑧ C語言關於復數
#include<stdio.h>
typedefstruct{
floatr;
floati;
}Complex;
ComplexreadComlexNumber(){
Complexn;
printf("Inputrealpart:");
scanf("%f",&n.r);
printf("Inputimaginarypart:");
scanf("%f",&n.i);
returnn;
}
ComplexsumComplex(Complexa,Complexb){
Complexc;
c.r=a.r+b.r;
c.i=a.i+b.i;
returnc;
}
ComplexdiffereneComplex(Complexa,Complexb){
Complexc;
c.r=a.r-b.r;
c.i=a.i-b.i;
returnc;
}
ComplexmultiplyComplex(Complexa,Complexb){
Complexc;
c.i=a.r*b.i+a.i*b.r;
c.r=a.r*b.r-a.i*b.i;
returnc;
}
ComplexdivideComplex(Complexa,Complexb){
Complexc;
c.r=(a.r*b.r+a.i*b.i)/(b.r*b.r+b.i*b.i);
c.i=(a.i*b.r-a.r*b.i)/(b.r*b.r+b.i*b.i);
returnc;
}
voidprintComplex(Complexn){
printf("%.2f+%.2fi",n.r,n.i);
}
intmain(){
Complexa,b,c;
printf("InputComplexnumbera: ");
a=readComlexNumber();
printf("InputComplexnumberb: ");
b=readComlexNumber();
printf("The2Complexa&bis: ");
printComplex(a);printf("and");printComplex(b);
//sum
c=sumComplex(a,b);
printf(" (a+b)=");printComplex(c);
//diff
c=differeneComplex(a,b);
printf(" (a-b)=");printComplex(c);
//multiply
c=multiplyComplex(a,b);
printf(" (a*b)=");printComplex(c);
//divide
c=divideComplex(a,b);
printf(" (a/b)=");printComplex(c);
return0;
}
⑨ 在C語言中,在VC程序中,復數如何表示
在FORTRAN語言中是有復數的。(最早的語言)
表示方法為(a,b)---a實部b虛部。FORTRAN語言可以復數計算。
在C語言中,在VC程序中可能是沒有的。
你要用可以自己在C語言中用復數計算規則自己擴展。VC程序擴展更方便了,類型與運算操作符重載。
⑩ 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;
}
(10)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;