我写的这个程序经常出现一些莫名其妙的问题,比如进入死循环或者当输入3个以上的复数进行乘法时,就会出错
所以只好来请教各位了
#include <stdio.h>
#include <conio.h>
void input( float (*p)[2], float sshu, float xshu, int *max );
void jiafa( float (*p)[2], float *sshu, float *xshu, int max );
void jianfa( float (*p)[2], float *sshu, float *xshu, int max );
void chengfa( float (*p)[2], float *sshu, float *xshu, int max );
void output( float (*p)[2], float sshu, float xshu, int max );
void putfushu( float (*p)[2], float sshu, float xshu, int max );
void main()
{
int k,max=0;
float p[10][2]={0}, sshu=0, xshu=0;
for ( ; ; )
{
printf("请选择一个你所需要的功能 :> 0 : 输出输入复数 ;1 : 加法运算 ;2 : 减法运算 ; 3 : 乘法运算;\n");
scanf("%d",&k);
void clrscr();
switch ( k )
{
case 0:input(p,sshu,xshu,&max);
putfushu(p,sshu,xshu,max);
break;
case 1:input(p,sshu,xshu,&max);
jiafa(p,&sshu,&xshu,max);
output(p,sshu,xshu,max);
break;
case 2:input(p,sshu,xshu,&max);
jianfa(p,&sshu,&xshu,max);
output(p,sshu,xshu,max);
break;
case 3:input(p,sshu,xshu,&max);
chengfa(p,&sshu,&xshu,max);
output(p,sshu,xshu,max);
break;
default:printf("错误的输入\n");
break;
}
}
}
void input(float (*p)[2], float sshu, float xshu, int *max)
{
int i;
printf(" 请输入有几组数参与运算\n");
scanf("%d",max);
for ( i=0; i < *max; i++)
{
printf("请输入第-- %d --组复数:eg--- xx.xx,xx.xx\n", i+1);
scanf("%f,%f",&p[i][0],&p[i][1]);
}
}
void jiafa( float (*p)[2], float *sshu, float *xshu, int max )
{
int i;
for ( i=0; i < max; i++ )
{
*sshu+=p[i][0];
*xshu+=p[i][1];
}
}
void jianfa( float (*p)[2], float *sshu, float *xshu, int max )
{
int i;
*sshu=p[0][0];
*xshu=p[0][1];
for ( i=1; i < max; i++ )
{
*sshu-=p[i][0];
*xshu-=p[i][1];
}
}
void chengfa( float (*p)[2], float *sshu, float *xshu, int max )
{
int i;
*sshu=p[0][0];
*xshu=p[0][1];
for ( i=1; i < max; i++ )
{
*sshu=*sshu*p[i][0]-*xshu*p[i][1];
*xshu=*sshu*p[i][1]+*xshu*p[i][0];
}
}
void output( float (*p)[2], float sshu, float xshu, int max )
{
printf(" 计算结果是 :%f", sshu);
if ( xshu >= 0)
printf("+i%f\n\n", xshu);
else
printf("-i%f\n\n",xshu*(-1));
}
void putfushu( float (*p)[2], float sshu, float xshu, int max )
{
int i;
for ( i=0; i < max; i++)
{
printf("你输入的复数为:%f", p[i][0]);
if ( p[i][1] >= 0)
printf("+i%f\n\n", p[i][1]);
else
printf("-i%f\n\n",p[i][1]*(-1));
}
}