急求!我的C语言代码运行不出结果,谁能帮帮我?

谁能帮我运行出结果啊,谢谢了!!/*------------子函数程序--------------*/#include<stdio.h>#include<stdlib.h... 谁能帮我运行出结果啊,谢谢了!!
/*------------子函数程序--------------*/
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#include <math.h>
#ifndef EPSILON
#define EPSILON 1.0e-10
#endif
int gseidel(double A[DIM][DIM],double b[DIM],double x[DIM])
{
static int first=0;
int i,j,k;
static double x1[DIM],norm;
norm=0.0;
if(first==0)
{
randomize();
for(i=0;i<DIM;i++)
{x[i]=rand();norm=norm+x[i]*x[i];}
norm=sqrt(norm);
for(i=0;i<DIM;i++)x[i]=x[i]/norm;
first=1;
}
for(k=0;k<MI;k++)
{
for(i=0;i<DIM;i++)
{
x1[i]=b[i];
for(j=0;j<i;j++) x1[i]=x1[i]-A[i][j]*x[j];
for(j=i+1;j<DIM;j++) x1[i]=x1[i]-A[i][j]*x[j];
x1[i]=x1[i]/A[i][i];
}
norm=0.0;
for(i=0;i<DIM;i++)norm=norm+(x1[i]-x[i])*(x1[i]-x[i]);
norm=sqrt(norm);
for(i=0;i<DIM;i++)x[i]=x1[i];
if(norm<EPSILON)goto endd;
}
endd:return(k);
}
/-----主程序函数-----/

#define DIM 4
#define MI 1000
#include "gseidel.c"
extern int gseidel(double A[DIM][DIM],double b[DIM],double x[DIM]);
void main(void)
{
int i,itime,iter;
char ifdoyn;
static double A[DIM][DIM]={{0.78,-0.02,-0.12,-0.14},
{-0.02,0.86,-0.04,0.06},{-0.12,-0.04,0.72,-0.08},{-0.14,0.06,-0.08,0.74}};
static double x[DIM],b[DIM]={0.76,0.08,1.12,0.68};
system("cls");
itime=0;
x[0]=4.0;x[1]=6.0;x[2]=8.0;(这个位置好像有错误,不知道怎么改)
printf("Gauss-Seidel iterative method:\n");
again:iter=gseidel(A,b,x);
itime=itime+iter;
if(iter<MI)itime=itime+1;
printf("Iterative %3d times.\n",itime);
for(i=0;i<DIM;i++)printf("%15.10f\n",x[i]);
if(iter<MI)
{
printf("Success!\n");
getch();
}
else
{
printf("If iterative again?(y/n)\n");
ifdoyn=getch();
if(ifdoyn=='y'||ifdoyn=='Y')goto again;
}

}
展开
 我来答
ccchu0
2008-05-31 · TA获得超过800个赞
知道小有建树答主
回答量:635
采纳率:0%
帮助的人:477万
展开全部
/*
randomize()是什么函数?
VC里貌似没这个,
VC用的是srand(),改了后在VC可以运行
*/
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#include <math.h>
#ifndef EPSILON
#define EPSILON 1.0e-10
#endif
#define DIM 4
#define MI 1000
int gseidel(double A[DIM][DIM],double b[DIM],double x[DIM])
{
static int first=0;
int i,j,k;
static double x1[DIM],norm;
norm=0.0;
if(first==0)
{
srand( (unsigned)time( NULL ) );
for(i=0;i<DIM;i++)
{x[i]=rand();norm=norm+x[i]*x[i];}
norm=sqrt(norm);
for(i=0;i<DIM;i++)x[i]=x[i]/norm;
first=1;
}
for(k=0;k<MI;k++)
{
for(i=0;i<DIM;i++)
{
x1[i]=b[i];
for(j=0;j<i;j++) x1[i]=x1[i]-A[i][j]*x[j];
for(j=i+1;j<DIM;j++) x1[i]=x1[i]-A[i][j]*x[j];
x1[i]=x1[i]/A[i][i];
}
norm=0.0;
for(i=0;i<DIM;i++)norm=norm+(x1[i]-x[i])*(x1[i]-x[i]);
norm=sqrt(norm);
for(i=0;i<DIM;i++)x[i]=x1[i];
if(norm<EPSILON)goto endd;
}
endd:return(k);
}

/* main.c */

//#include "gseidel.c"
void main(void)
{
int i,itime,iter;
char ifdoyn;
static double A[DIM][DIM]={{0.78,-0.02,-0.12,-0.14},
{-0.02,0.86,-0.04,0.06},{-0.12,-0.04,0.72,-0.08},{-0.14,0.06,-0.08,0.74}};
static double x[DIM],b[DIM]={0.76,0.08,1.12,0.68};
system("cls");
itime=0;
x[0]=4.0;
x[1]=6.0;
x[2]=8.0;
printf("Gauss-Seidel iterative method:\n");
again:iter=gseidel(A,b,x);
itime=itime+iter;
if(iter<MI)itime=itime+1;
printf("Iterative %3d times.\n",itime);
for(i=0;i<DIM;i++)printf("%15.10f\n",x[i]);
if(iter<MI)
{
printf("Success!\n");
getch();
}
else
{
printf("If iterative again?(y/n)\n");
ifdoyn=getch();
if(ifdoyn=='y'||ifdoyn=='Y')goto again;
}

}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2008-05-30
展开全部
做如下修改后,可以正常运行,屏幕显示:
Gauss-Seidel iterative method:
Iterative 21 times.
1.5349650349
0.1220095694
1.9751564225
1.4129554656
Success!

/* gseidel.c */

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#include <math.h>
#ifndef EPSILON
#define EPSILON 1.0e-10
#endif
#define DIM 4
#define MI 1000
int gseidel(double A[DIM][DIM],double b[DIM],double x[DIM])
{
static int first=0;
int i,j,k;
static double x1[DIM],norm;
norm=0.0;
if(first==0)
{
randomize();
for(i=0;i<DIM;i++)
{x[i]=rand();norm=norm+x[i]*x[i];}
norm=sqrt(norm);
for(i=0;i<DIM;i++)x[i]=x[i]/norm;
first=1;
}
for(k=0;k<MI;k++)
{
for(i=0;i<DIM;i++)
{
x1[i]=b[i];
for(j=0;j<i;j++) x1[i]=x1[i]-A[i][j]*x[j];
for(j=i+1;j<DIM;j++) x1[i]=x1[i]-A[i][j]*x[j];
x1[i]=x1[i]/A[i][i];
}
norm=0.0;
for(i=0;i<DIM;i++)norm=norm+(x1[i]-x[i])*(x1[i]-x[i]);
norm=sqrt(norm);
for(i=0;i<DIM;i++)x[i]=x1[i];
if(norm<EPSILON)goto endd;
}
endd:return(k);
}

/* main.c */

#include "gseidel.c"
void main(void)
{
int i,itime,iter;
char ifdoyn;
static double A[DIM][DIM]={{0.78,-0.02,-0.12,-0.14},
{-0.02,0.86,-0.04,0.06},{-0.12,-0.04,0.72,-0.08},{-0.14,0.06,-0.08,0.74}};
static double x[DIM],b[DIM]={0.76,0.08,1.12,0.68};
system("cls");
itime=0;
x[0]=4.0;
x[1]=6.0;
x[2]=8.0;
printf("Gauss-Seidel iterative method:\n");
again:iter=gseidel(A,b,x);
itime=itime+iter;
if(iter<MI)itime=itime+1;
printf("Iterative %3d times.\n",itime);
for(i=0;i<DIM;i++)printf("%15.10f\n",x[i]);
if(iter<MI)
{
printf("Success!\n");
getch();
}
else
{
printf("If iterative again?(y/n)\n");
ifdoyn=getch();
if(ifdoyn=='y'||ifdoyn=='Y')goto again;
}

}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式