#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
printf("请输入整数n(1<n<50)\n");
int n = 0;
scanf_s("%d", &n);
int arr[50] = { 0 };
int i = 0;
printf("请输入你要存放的数。\n");
for (i = 0; i < n; i++)//给数组赋值
{
scanf_s("%d", &arr[i]);
}
printf("请输入你要删除的数:");
int b = 0;
scanf_s("%d", &b);
int c = 0;
while ( c< n)//实现数组与将要删除数的一个检索和对比
{
if (b == arr[c])
{
for (c; c < n; c++)
{
arr[c] = arr[c + 1];
}
}
c++;
}
int d = 0;
for (d = 0; d < n-1; d++)//输出,这里的n-1是为了不让最后一位随机数被打印出来
{
printf("%d ", arr[d]);
}
return 0;
}
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
printf("请输入整数n(1<n<50)\n");
int n = 0;
scanf_s("%d", &n);
int arr[50] = { 0 };
int i = 0;
printf("请输入你要存放的数。\n");
for (i = 0; i < n; i++)//给数组赋值
{
scanf_s("%d", &arr[i]);
}
printf("请输入你要删除的数:");
int b = 0;
scanf_s("%d", &b);
int c = 0;
while ( c< n)//实现数组与将要删除数的一个检索和对比
{
if (b == arr[c])
{
for (c; c < n; c++)
{
arr[c] = arr[c + 1];
}
}
c++;
}
int d = 0;
for (d = 0; d < n-1; d++)//输出,这里的n-1是为了不让最后一位随机数被打印出来
{
printf("%d ", arr[d]);
}
return 0;
}