C/C++の宿題を片付けます 93代目
at TECH
[
2ch
|
▼Menu
]
■コピペモード
□
スレを通常表示
□
オプションモード
□このスレッドのURL
■項目テキスト
850:デフォルトの名無しさん 07/07/24 23:00:02 >構造体COMPLEXを構造体で定義する。 構造体を構造体以外でどうやって定義するんだよw 851:デフォルトの名無しさん 07/07/25 00:00:30 >>848 ほい。名前が適当だから、そこだけ自分で修正して。 #include <stdio.h> typedef struct{ double r; double i; } comp; comp add_comp(comp c1,comp c2){ comp tmp; tmp.r=c1.r+c2.r; tmp.i=c1.i+c2.i; return tmp; } comp mul_comp(comp c1,comp c2){ comp tmp; tmp.r=c1.r*c2.r-c1.i*c2.i; tmp.i=c1.r*c2.i+c1.i*c2.r; return tmp; } 852:デフォルトの名無しさん 07/07/25 00:01:35 >>851の続き int main(){ comp c1={2.0,3.0}; comp c2={4.0,-2.0}; comp result; printf("1つ目の複素数(実部):%lf\n",c1.r); printf("1つ目の複素数(虚部):%lf\n",c1.i); printf("2つ目の複素数(実部):%lf\n",c2.r); printf("2つ目の複素数(虚部):%lf\n",c2.i); result=add_comp(c1,c2); printf("足し算:(%lf)+(%lf)i\n",result.r,result.i); result=mul_comp(c1,c2); printf("かけ算:(%lf)+(%lf)i\n",result.r,result.i); return 0; }
次ページ
最新レス表示
スレッドの検索
類似スレ一覧
話題のニュース
おまかせリスト
▼オプションを表示
レスジャンプ
mixiチェック!
Twitterに投稿
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch
5395日前に更新/328 KB
担当:undef