我在编写一个c语言删除数组的程序,就输入数组中的一个数,然后将其删除,我的代码如下:
#include<stdio.h>intmain(){inthappy[]={34,56,33,77,22};inti,j=5;intdelethappy;intdele...
#include <stdio.h>
int main()
{
int happy[] = {34,56,33,77,22};
int i,j = 5;
int delethappy;
int deletindex = -1;
printf("请输入要删除的数:");
scanf("%d",&delethappy);
for(i = 0;i < j;i++)
{
if(delethappy == happy[i]);
{
deletindex = i;
break;
}
}
if(-1 == deletindex)
{
printf("failure\n");
}
else
{
for(i = deletindex;i < j -1;i++)
{
happy[i] = happy[i + 1];
}
j--;
}
printf("数值:\n");
for(i = 0;i < j;i++)
{
printf("%d\t",happy[i]);
}
return 0;
}
结果无论输入什么数,打印的值都是 56 33 77 22
各位大佬帮忙看看出了什么问题 展开
int main()
{
int happy[] = {34,56,33,77,22};
int i,j = 5;
int delethappy;
int deletindex = -1;
printf("请输入要删除的数:");
scanf("%d",&delethappy);
for(i = 0;i < j;i++)
{
if(delethappy == happy[i]);
{
deletindex = i;
break;
}
}
if(-1 == deletindex)
{
printf("failure\n");
}
else
{
for(i = deletindex;i < j -1;i++)
{
happy[i] = happy[i + 1];
}
j--;
}
printf("数值:\n");
for(i = 0;i < j;i++)
{
printf("%d\t",happy[i]);
}
return 0;
}
结果无论输入什么数,打印的值都是 56 33 77 22
各位大佬帮忙看看出了什么问题 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询