C语言数组连接的问题

来源:百度知道 编辑:UC知道 时间:2024/05/20 01:03:30
#include "stdio.h"
main()
{ int n,l,t,i;
double a[100];
double b[100];
double c[100];
clrscr();
printf(" >> Please input the order n of matrix a (>1): ");
scanf("%d",&n);
printf(" >> Please input the %d elements of matrix a(%d*%d) one by one:\n",n*n,n,n);
for(i=0;i<n*n;i++)
scanf("%lf",&a[i]);
printf(" >> Please input the %d elements of matrix b(%d*1) one by one:\n",n,n);
for(i=0;i<n;i++)
scanf("%lf",&b[i]);
for(t=0;t<=n-1;t++)
{
for(l=0;1<=n-1;l++)
{
c[t*(n+2)+l]=a[t*(n+1)];
}
c[(t+1)*(n+2)-1]=b[t];
}
for(i=0;i<=n*(n+1)-1;i++)
printf("c[%d]=%f ",i,c[i]);
puts("\n Press any key to quit...");
getch();
}
把a,b

#include<stdio.h>
#include<conio.h>
main()
{int n,l,t,i;
double a[100],b[100],c[100];
printf(" >> Please input the order n of matrix a (>1): ");
scanf("%d",&n);
printf(" >> Please input the %d elements of matrix a(%d*%d) one by one:\n",n*n,n,n);
for(i=0;i<n*n;i++)
scanf("%lf",&a[i]);
printf(" >> Please input the %d elements of matrix b(%d*1) one by one:\n",n,n);
for(i=0;i<n;i++)
scanf("%lf",&b[i]);
for(t=0;t<=n-1;t++)
{
for(l=0;l<=n-1;l++)
{
c[t*(n+1)+l]=a[t*n+l];
}
c[t*(n+1)+n]=b[t];
}
for(i=0;i<=n*(n+1)-1;i++)
printf("c[%d]=%lf ",i,c[i]);
puts("\n Press any key to quit...");
getch();
}
这是我把你的程序稍微修改后得到的没问题了.我把清屏命令去掉了,因为编译时不知为什么总说clrscr()是一个未声明的函数. 另外,要用clrscr和getch需打开conio.h. 还有,你程序中的for(l=0