当前位置:网站首页>删除所有值为y的元素。数组元素中的值和y的值由主函数通过键盘输入。
删除所有值为y的元素。数组元素中的值和y的值由主函数通过键盘输入。
2022-07-04 00:34:00 【CTGU-Yoghurt】
题目:
删除所有值为y的元素。数组元素中的值和y的值由
主函数通过键盘输入。
代码详解:
#include <stdio.h>
#include<conio.h>
#include<stdio.h>
#define M 20
void fun(int bb[], int* n, int y)
{
/**********Program**********/
for (int i = 0; i < *n;)
{
if (bb[i] == y) {
for (int j = i; j < *n; j++)
{
bb[j] = bb[j + 1];
}
(* n)--;//注:--的优先级在*的前面,所以用括号展开
}
else i++;
}
/********** End **********/
}
int main()
{
int aa[M], n, y, k;
printf("\nPlease enter n:"); scanf("%d", &n);
printf("\nEnter %d positive number:\n", n);
for (k = 0; k < n; k++) scanf("%d", &aa[k]);
printf("The original data is:\n");
for (k = 0; k < n; k++) printf("%5d", aa[k]);
printf("\nEnter a number to deletede:"); scanf("%d", &y);
fun(aa, &n, y);
printf("The data after deleted %d:\n", y);
for (k = 0; k < n; k++) printf("%4d", aa[k]);
printf("\n");
return 0;
}
边栏推荐
- 12. Go implementation of integer to Roman numeral and leetcode
- Introducing Software Testing
- SPI based on firmware library
- Detailed explanation of the relationship between Zhongtai, wechat and DDD
- A dichotomy of Valentine's Day
- MySQL 8.0.12 error: error 2013 (HY000): lost connection to MySQL server during query
- Selenium library 4.5.0 keyword explanation (I)
- [NLP] text classification still stays at Bert? Duality is too strong than learning framework
- P1629 postman delivering letter
- The difference between objects and objects
猜你喜欢
Iclr2022: how does AI recognize "things I haven't seen"?
[2021]NeRF in the Wild: Neural Radiance Fields for Unconstrained Photo Collections
A dichotomy of Valentine's Day
What is regression testing? Talk about regression testing in the eyes of Ali Test Engineers
Report on prospects and future investment recommendations of China's assisted reproductive industry, 2022-2028 Edition
Sorry, Tencent I also refused
Software testers, how can you quickly improve your testing skills? Ten minutes to teach you
手机异步发送短信验证码解决方案-Celery+redis
[cloud native topic -48]:kubesphere cloud Governance - operation - overview of multi tenant concept
[complimentary ppt] kubemeet Chengdu review: make the delivery and management of cloud native applications easier!
随机推荐
It is worthy of "Alibaba internal software test interview notes" from beginning to end, all of which are essence
Global and Chinese market of process beer equipment 2022-2028: Research Report on technology, participants, trends, market size and share
For loop
Kubedl hostnetwork: accelerating the efficiency of distributed training communication
Speed up the energy Internet of things. What can low-power Internet of things technology represented by Zeta do?
Eight year test old bird, some suggestions for 1-3 year programmers
功能:将主函数中输入的字符串反序存放。例如:输入字符串“abcdefg”,则应输出“gfedcba”。
2020.2.14
P1656 bombing Railway
[Mongodb] 2. Use mongodb --------- use compass
Pytorch learning notes 5: model creation
Is user authentication really simple
[PHP basics] cookie basics, application case code and attack and defense
12. Go implementation of integer to Roman numeral and leetcode
Anomalies seen during the interview
The difference between objects and objects
STM32 key light
MySQL is installed as a Windows Service
How to be a professional software testing engineer? Listen to the byte five year old test
Regular expressions and text processors for shell programming