C语言容错程序,[求助]用C语言编的求规范正交基,已实现,但有个小的容错搞不定...

谢谢,我感觉我的算法是正确的.

而且我无意中实现了,我把xishuc函数合并到了schmidt函数里,居然就可以正常运算了!我也不知道为什么。我一直以为Turbo C是莫名其妙的。但不管它了。

我还有一个问题,和线性代数无关的。我现在已经可以算出规范正交基了,但还想搞个小的容错.就是我想在用scanf函数输入了m后,加一个对m不是数字的容错,用printf输出Please input a number!

我原本打算用isdigit,但发现它是测试字符型数据的。对我的int型的m变量的测试结果根本是乱七八糟。我在网上查到有用字符串数组测试的,但如果那样,那就无法使用变量m了。所以现在可以用束手无策来形容我了。

所以我想请教高手,如何加这样的一个容错。给我指个方向好吗?提示一下,谢谢了!

以下是我改好的代码:

/*guifanzhengjiaoji*/

#include

#include

#include

#include

float a[10][10];

float b[10][10];

int m,n;

float vemulti(int g,int l) /*vector multiply*/

{

int i;

float r=0;

if(g>=0&&g=0&&l

for(i=0;i

r+=a[i][g]*a[i][l];

return r;}

else printf("Row number is wrong!");

}

void schmidt(int g)

{

float w,sh,xia;

int i,j;

for(j=0;j

sh=vemulti(j,g);

xia=vemulti(j,j);

if(xia!=0){

w=sh/xia;

w=w*(-1);

for(i=0;i

b[i][j]=a[i][j]*w;}

else{

printf("Vectors like these is prohibited!\n");

exit(0);}

}

for(j=0;j

for(i=0;i

a[i][g]=a[i][g]+b[i][j];}

}

void biaozhun(int g)

{

float w;

float y;

int i;

w=vemulti(g,g);

y=sqrt(w);

if(y!=0){

y=1/y;

for(i=0;i

a[i][g]*=y;

}

else{

printf("Vectors like these is prohibited!\n");

exit(0);}

}

main()

{

int i,j;

printf("put in the number of every vector:\n");

scanf("%d",&m);

printf("how many vectors do you want:\n");

scanf("%d",&n);

if(m<=10&&m>=1&&n<=10&&n>1)

{

for(j=0;j

{

for (i=0;i

{

printf("input %d number of vector %d:",i+1,j+1);

scanf("%f",&a[i][j]);/*2*/

}

}

}

else if (n=1) {

printf("Vectors like this is prohibited!");

exit(0);}

else{

printf("Please input a number which is less than 11 and more than 0!");

exit(0);}

for(j=1;j

schmidt(j);

}

for(j=0;j

biaozhun(j);

printf("the result is:\n");

for(i=0;i

for(j=0;j

printf("%-6.3f ",a[i][j]);}

printf("\n");}

}

[此贴子已经被作者于2007-1-3 21:09:08编辑过]

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值