从键盘输入整型一维数组中a中的各元素(以元素0结束,0是最后一个有效果元素,元素个数不超过20个),再输

2024-11-19 08:30:15
推荐回答(4个)
回答1:

#include "stdio.h"
main()
{
int a[20];
int i=0,k=0;
while(1)
{
scanf("%d",&a[i]);
k++;
if(a[i]==0)
break;
i++;
}
for(i=0;i printf("%5d",a[i]);
}

回答2:

#include

int main(void)
{
int a[20];
int n = 0, i, j, d, flag = 0;

while (scanf("%d", &a[n]) == 1 && a[n++] != 0);

scanf("%d", &d);

for (i = 0; i < n; i++)
printf("%5d", a[i]);

printf("\n");
for (i = 0; i < n; i++)
{
if (a[i] == d)
{
for (j = i; j < n - 1; j++)
{
a[j] = a[j + 1];
flag = 1;
}
n--;
i--;
}
}

if (flag)
{
for (i = 0; i < n; i++)
printf("%5d", a[i]);
printf("\n");
}
else printf("does not exist,no operating!\n");
return 0;
}

回答3:

#include
int main( )
{
int a[20]={0},i=0,j=0,temp=0,flag=0;
printf("请输入并以0 结尾\n");
for(i=0;i<20;++i)
{
scanf("%d",&a[i]);
if(a[i]==0)
break;
}
printf("有%d个数字\n",i+1);
for(j=0;j<=i;++j)
{
printf("%d\n",a[j]);
}
printf("输入要删除的数\n");
scanf("%d",&temp);
for(j=0;j<=i;++j)
{
if(a[j]==temp)
{
a[j]=-1;
flag=1;
}
}
if(flag==0)
printf("does not exist,no operating!\n");
else
{
printf("删除后\n");
for(j=0;j<=i;++j)
{
if(a[j] != -1)
printf("%d\n",a[j]);
}
}
return 0;
}

回答4:

没分这么难的题谁答啊...,好歹悬赏几分啊...