c言語で複素数の四則演算を行うプログラムを作成しています。
とりあえずは、足し算と引き算の処理を行うプログラムを作成しようと思っています。
現在、途中まで書き終えているのが以下のコードです。
c
1 2#include<stdio.h> 3#define N 2 4 5 6typedef struct Complex { 7 double real; 8 double imaginary; 9}Complex; 10 11Complex complex[N] = { 0.0 }; 12 13//int? add(Complex *Pc1, Complex *Pc2); 14//int? sub(Complex *Pc1, Complex *Pc2); 15//int? mul(Complex *Pc1, Complex *Pc2); 16//int? divi(Complex *Pc1, Complex *Pc2); 17 18int main() { 19 int cond; 20 int i; 21 22 for (i = 0; i < N; i++) { 23 printf("Please Input Complex%d Real :", i + 1); 24 printf("Please Input Complex%d Imaginary :", i + 1); 25 scanf("%d", &complex[i].real); 26 scanf("%d", &complex[i].imaginary); 27 } 28 printf("Please Input Operator :"); 29 scanf("%d", &cond); 30//if(cond==1)add(&conplex[0],&conplex[1]) 31//if(cond==2)sub(&conplex[0],&conplex[1]) 32 33 return 0; 34} 35 36 37//int? add(Complex *Pc1, Complex *Pc2) { 38 Complex rezult; 39 rezult.real = Pc1->real + Pc2->real; 40 rezult.imaginary = Pc1->imaginary + Pc2->imaginary; 41} 42//int? sub(Complex *Pc1, Complex *Pc2) { 43 Complex rezult; 44 rezult.real = Pc1->real - Pc2->real; 45 rezult.imaginary = Pc1->imaginary - Pc2->imaginary; 46}
それで、疑問点が一つあります。
add関数、sub関数で構造体rezultのポインタを返すには、関数は何型にするべきでしょうか?
int型では不可能ですか?
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/13 01:18