当前位置:网站首页>C language sorts n integers with pointers pointing to pointers
C language sorts n integers with pointers pointing to pointers
2022-07-29 08:25:00 【CPP programming】
C Language uses the method of pointer to pointer n Sort an integer and output ; It is required to write the sorting as a separate function ;n Enter an integer in the main function , Finally, output... In the main function .
Their thinking : As the reader looks at the question , First of all, observe the rules , Then the pointer pointing to the pointer has paved the way in the last exercise , Readers can contact a problem to skillfully use the pointer pointing to the pointer .
C Language source code demonstration :
#include<stdio.h>// The header file
int main()// The main function
{
void sort(int **point,int number); //sort Sort function declaration
int i,number,data[20],**point,*pstr[20]; // Defining variables
printf(" Enter the number to sort number:");// Prompt statement
scanf("%d",&number);// Keyboard entry
for(i=0;i<number;i++)
{
pstr[i]=&data[i]; // Will be the first i The address of an integer is given to the pointer array pstr Of the i Elements
}
printf(" Enter this one by one %d Number :",number);// Prompt statement
for(i=0;i<number;i++)
{
scanf("%d",pstr[i]);// Enter the number to sort one by one
}
point=pstr;
sort(point,number);
printf("\n-------------------\n"); // Prompt statement
printf(" Output results :\n");// Prompt statement
for(i=0;i<number;i++)
{
printf("%d ",*pstr[i]);// Output the sorted result
}
printf("\n");// Line break
return 0;// The return value of the main function is 0
}
void sort(int **point,int number)// Customize sort Sorting function
{
int i,j,*temp;// Defining variables
for(i=0;i<number-1;i++)
{
for(j=i+1;j<number;j++)
{
if(**(point+i)>**(point+j))// Exchange integer addresses after comparison
{
temp=*(point+i);
*(point+i)=*(point+j);
*(point+j)=temp;
}
}
}
}
Compile run results :
Enter the number to sort number:3
Enter this one by one 3 Number :1 8 5
-------------------
Output results :
1 5 8
--------------------------------
Process exited after 6.278 seconds with return value 0
Please press any key to continue . . .
Today's sharing is here , Everyone should study hard C Language /C++ yo ~
At the end : For preparing to learn C/C++ Programming partners , If you want to better improve your core programming skills ( Internal skill ) From now on !
C Language C++ Programming learning communication circle ,QQ Group :763855696【 Click to enter 】
C Language from entry to mastery (C Introduction to language C Language course C Language zero basis C Language foundation C Language learning C
Organize and share ( Years of learning source code 、 Project practice video 、 Project notes , Introduction to Basics )
Welcome to change careers and learn programming partners , Using more information to learn and grow faster than thinking about it yourself !
Programming learning video sharing :


边栏推荐
- Qt/pyqt window type and window flag
- Alibaba political commissar system - Chapter III, Alibaba political commissar and cultural docking
- Centos7/8 command line installation Oracle11g
- Time function in MySQL
- Smart energy management system solution
- NFC two-way communication 13.56MHz contactless reader chip -- si512 replaces pn512
- Background management system platform of new energy charging pile
- Day15: the file contains the vulnerability range manual (self use file include range)
- Random lottery turntable wechat applet project source code
- Day5: PHP simple syntax and usage
猜你喜欢

Four pin OLED display based on stm32

110道 MySQL面试题及答案 (持续更新)

Noise monitoring and sensing system

HC-SR04超声波测距模块使用方法和例程(STM32)

谷歌浏览器免跨域配置

随机抽奖转盘微信小程序项目源码

深度学习(2):图片文字识别

Compatible with cc1101/cmt2300-dp4301 sub-1g wireless transceiver chip

User identity identification and account system practice

PostgreSQL手动创建HikariDataSource解决报错Cannot commit when autoCommit is enabled
随机推荐
Ar virtual augmentation and reality
Clickhouse learning (III) table engine
Cv520 domestic replacement of ci521 13.56MHz contactless reader chip
Day6: using PHP to write landing pages
搜索与回溯经典题型(八皇后)
【Transformer】SegFormer:Simple and Efficient Design for Semantic Segmentation with Transformers
Basic crawler actual combat case: obtaining game product data
Day6: use PHP to write file upload page
110道 MySQL面试题及答案 (持续更新)
Clickhouse learning (I) Clickhouse?
Huawei wireless device configuration uses WDS technology to deploy WLAN services
centos7/8命令行安装Oracle11g
Unity shader learning (VI) achieving radar scanning effect
Low cost 2.4GHz wireless transceiver chip -- ci24r1
产品推广的渠道和策略,化妆品品牌推广方法及步骤
AES 双向加密解密工具
Component transfer participation lifecycle
Phy6252 is an ultra-low power Bluetooth wireless communication chip for the Internet of things
Simple calculator wechat applet project source code
Tensorboard use