c语言程序 数组a有10个元素,从a中第二个元素起,分别将后项减前项之差存入数组b中,并按每行3个元素输出b

2024-12-03 03:09:07
推荐回答(3个)
回答1:

#include
int main()
{
int a[10] = {1,2,3,4,5,6,7,8,9,10};
int b[9];
int i;
for ( i = 0; i < 9; i++)
{
b[i] = a[i+1] - a[i];

if (0 == i % 3)
{
printf("\n");
}

printf("%d",b[i]);
}

printf("\n");

return 0;
}

回答2:

#include
#define N 10
int main(void)
{
int a[N]={4,2,7,3,8,6,7,20,9,17},b[N-1],i,j,k=0;
for(i=1;i{
b[i]=a[i+1]-a[i];
}
for(j=1;j{
printf("%4d",b[j]);
k++;
if(k%3==0)
{
printf("\n");
}
}
return(0);
}

回答3:

#include
#define n 10
void main()
{
int a[n],b[n-1],i,j,k=0;
printf ("输入10个数:\n");
for (i=0;i{
printf ("a[%d]= ",i);
scanf ("%d",&a[i]);
}
for(i=0,j=0;i{
b[j]=a[i+1]-a[i];
}
for(j=0;j{
printf("%5d",b[j]);
k++;
if(k%3==0)
{
printf("\n");
}
}
}