当前位置:网站首页>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 :


边栏推荐
- Implementation of support vector machine with ml11 sklearn
- Simulation of four way responder based on 51 single chip microcomputer
- Day5: PHP simple syntax and usage
- Clickhouse learning (III) table engine
- Basic shell operations (Part 2)
- Leetcode Hot 100 (brush question 9) (301/45/517/407/offer62/mst08.14/)
- Qt/pyqt window type and window flag
- 2.4G band wireless transceiver chip si24r1 summary answer
- Brief introduction and use of commonjs import and export and ES6 modules import and export
- Compatible with cc1101/cmt2300-dp4301 sub-1g wireless transceiver chip
猜你喜欢

Multifunctional signal generator based on AD9850

数字人民币时代隐私更安全

Cs4344 domestic substitute for dp4344 192K dual channel 24 bit DA converter

Day6: use PHP to write file upload page

Stm32ff030 replaces domestic MCU dp32g030

Simple calculator wechat applet project source code

Security baseline of network security

DC motor control system based on DAC0832

Deep learning (1): prediction of bank customer loss

Basic shell operations (Part 1)
随机推荐
Application scheme of charging pile
Preparation of SQL judgment statement
Implementation of support vector machine with ml11 sklearn
torch.Tensor和torch.tensor的区别
Proteus simulation based on msp430f2491
torch.nn.functional.one_hot()
深度学习(1):银行客户流失预测
Play Parkour with threejs Technology
Basic shell operations (Part 1)
TCP - sliding window
STM32 MDK (keil5) contents mismatch error summary
Eps32+platform+arduino running lantern
Clickhouse learning (III) table engine
Search and recall classic questions (eight queens)
Unity multiplayer online framework mirror learning record (I)
Ga-rpn: recommended area network for guiding anchors
Dp4301-sub-1g highly integrated wireless transceiver chip
Intelligent temperature control system
Charging pile charging technology new energy charging pile development
Unity多人联机框架Mirro学习记录(一)