当前位置:网站首页>删除所有值为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
- The culprit of unrestrained consumption -- Summary
- Why use get/set instead of exposing properties
- [NLP] text classification still stays at Bert? Duality is too strong than learning framework
- Iclr2022: how does AI recognize "things I haven't seen"?
- What are the application fields of digital twins in industry?
- 功能:将主函数中输入的字符串反序存放。例如:输入字符串“abcdefg”,则应输出“gfedcba”。
- Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
- ESP Arduino playing with peripherals (V) basic concept of interrupt and timer interrupt
- What is the GPM scheduler for go?
猜你喜欢

老姜的特点

Sorry, Tencent I also refused
![[C language] break and continue in switch statement](/img/ae/5967fefcf3262c9d3096e5c7d644fd.jpg)
[C language] break and continue in switch statement

Private project practice sharing populate joint query in mongoose makes the template unable to render - solve the error message: syntaxerror: unexpected token r in JSON at

Vscode regular match replace console log(.*)

A method to solve Bert long text matching

The difference between objects and objects

China standard gas market prospect investment and development feasibility study report 2022-2028

Detailed explanation of the relationship between Zhongtai, wechat and DDD

Data mining vs Machine Learning: what is the difference between them? Which is more suitable for you to learn
随机推荐
[error record] configure NDK header file path in Visual Studio
Pair
Global and Chinese market of melting furnaces 2022-2028: Research Report on technology, participants, trends, market size and share
MySQL is installed as a Windows Service
Reading notes on how programs run
打印菱形图案
Yyds dry goods inventory three JS source code interpretation - getobjectbyproperty method
The difference between objects and objects
How to be a professional software testing engineer? Listen to the byte five year old test
On the day when 28K joined Huawei testing post, I cried: everything I have done in these five months is worth it
Zipper table in data warehouse (compressed storage)
Briefly understand the operation mode of developing NFT platform
不得不会的Oracle数据库知识点(二)
What is the GPM scheduler for go?
Stock price forecast
What is the potential of pocket network, which is favored by well-known investors?
Solution to the impact of Remote Code Execution Vulnerability of log4j2 component on December 9, 2021
A Kuan food rushed to the Shenzhen Stock Exchange: with annual sales of 1.1 billion, Hillhouse and Maotai CCB are shareholders
A dichotomy of Valentine's Day
Selenium library 4.5.0 keyword explanation (II)