满意答案
jsocf
2013.08.04
采纳率:48% 等级:9
已帮助:464人
#include
void main()
{
float shibu,xubu;
char op,op_i;
scanf("%f",&shibu);
op=getchar();
if(op!='\0')
{
if(op!='+'&&op!='-')
{
printf("输入错误\n");
getchar();
return;
}
scanf("%f",&xubu);
op_i=getchar();//接受随后输入的i
if(op_i!='i')
{
printf("输入错误,复数结尾有i\n");
getchar();
return;
}
if(op=='+')
op='-';
else
op='+'; printf("\n%f%c%fi\n",shibu,op,xubu);
getchar();
}
else//输入一个整数然后回车,没有虚部
{
printf("%f\n",shibu);
}
getchar();getchar();} 和用没有用数组没有关系.考虑到一个复数最多由四部分构成,实部,虚部,符号,和i.//分别用不同的变量装着,然后,将符号进行变号就行了./
01分享举报