当前位置:网站首页>[C exercise] delete the specified number in the sequence
[C exercise] delete the specified number in the sequence
2022-07-18 01:40:00 【Domeecky】
example :“1,2,3,4,5,4,6,4”( Array elements ), Input :4( Number of to delete ), Output :“1,2,3,5,6”
int main()
{
int arr[8] = { 1,2,3,4,5,4,6,4 };
int del = 0;
int sz = sizeof(arr) / sizeof(arr[0]);
int j = 0;
for (int i = 0; i < sz; i++)// Print array
{
printf("%d ", arr[i]);
}
printf("\n");
scanf("%d", &del);// Enter the number to delete
for (int i = 0; i < sz; i++)
{
if (arr[i] != del)
arr[j++] = arr[i];//j++ First of all j The subscript element is changed to i Subscript elements , let j Skip an element
}
for (int i = 0; i < j; i++)
{
printf("%d ", arr[i]);
}
return 0;
}边栏推荐
猜你喜欢
随机推荐
System. Use of arraycopy and detailed explanation of parameter meaning
【C 练习】序列中删除指定的数字
求字符串长度
Solution of in multi column special query type in laravel
Good people are late acquaintances
Matlab low-level source code realizes Prewitt edge detection and Sobel, Laplace edge detection (the implementation effect is consistent with Halcon)
树莓派 安装 opencv 环境,解决NO module named ‘cv2’
Online multi line text batch regular replacement add suffix tool
AB test command
【HCIA】OSI 模型
How can Volvo be confident to maintain "zero casualties" in traffic safety in the era of electrification?
【C 练习】打印菱形
ab测试命令
字符串相关函数和内存相关函数的实现
树莓派串口通信
redis持久化之aof
Development practice - reasoning application development experience of shengteng cann
What is website ICP filing?
Realization of greedy snake in C language
【C 练习】变种水仙花数









