問題で・・・
Posted: 2006年12月19日(火) 21:11
フェーザ表記のインピーダンスをコマンドライン引数として入力し、アドミタンスYに変換して成分表示するプログラムを作るのですが・・・
main関数の二つ目のprintfのところの表示が整数ででてきてしまいます。
デバッガで見てもよくわかりませんでした。
ifの条件は少ないですがあとでたすつもりです。
大まかな構造は変えないで教えていただけると幸いです。
main関数の二つ目のprintfのところの表示が整数ででてきてしまいます。
デバッガで見てもよくわかりませんでした。
ifの条件は少ないですがあとでたすつもりです。
大まかな構造は変えないで教えていただけると幸いです。
#include <stdio.h> #include <stdlib.h> struct complex_p { double a; double b; }; struct complex_p cp_p( struct complex_p *a, struct complex_p *b); int main( int argc, char *argv[/url] ) { struct complex_p c1={0.0,0.0}, c2={0.0,0.0}, c3; char n1,n2; if(argc<2) { printf("Error. The number of argument is too few..\n"); return(-1); } n1=*argv[1]; n2=*argv[2]; c1.a=atof(argv[1]); c2.b=atof(argv[2]); if((n1=='1'|| n1=='2'||n1=='3'||n1=='4'||n1=='5'||n1=='6'||n1=='7'||n1=='8'||n1=='9')&&(n2=='1'|| n2=='2'||n2=='3'||n2=='4'||n2=='5'||n2=='6'||n2=='7'||n2=='8'||n2=='9')){ c3 = cp_p(&c1,&c2); printf("Z=%g-j%g.\n",c1.a, c2.b ); printf("Y=%g+j%g.\n",c2.a, c1.b ); } return (0); } struct complex_p cp_p(struct complex_p *a, struct complex_p *b) { struct complex_p tmp; tmp.a = (*a).a / ((*a).a * (*a).a + (*b).b * (*b).b); tmp.b = (*b).b / ((*a).a * (*a).a + (*b).b * (*b).b); return tmp; }