当前位置:网站首页>C语言用指向指针的指针对n个整数排序
C语言用指向指针的指针对n个整数排序
2022-07-29 05:08:00 【cpp编程】
C语言用指向指针的指针的方法对n个整数排序并输出;要求将排序单独写成一个函数;n个整数在主函数中输入,最后在主函数中输出。
解题思路:读者看着道题的时候,首先要观察一下有什么规律,然后指向指针的指针在上一道练习题中已经有了铺垫,读者可以联系上一道题去熟练使用指向指针的指针。
C语言源代码演示:
#include<stdio.h>//头文件
int main()//主函数
{
void sort(int **point,int number); //sort排序函数声明
int i,number,data[20],**point,*pstr[20]; //定义变量
printf("输入要排序的个数number:");//提示语句
scanf("%d",&number);//键盘输入
for(i=0;i<number;i++)
{
pstr[i]=&data[i]; //将第i个整数的地址赋予指针数组pstr的第i个元素
}
printf("逐个输入这%d个数:",number);//提示语句
for(i=0;i<number;i++)
{
scanf("%d",pstr[i]);//挨个输入要排序的数
}
point=pstr;
sort(point,number);
printf("\n-------------------\n"); //提示语句
printf("输出结果:\n");//提示语句
for(i=0;i<number;i++)
{
printf("%d ",*pstr[i]);//输出排序后的结果
}
printf("\n");//换行
return 0;//主函数返回值为0
}
void sort(int **point,int number)//自定义sort排序函数
{
int i,j,*temp;//定义变量
for(i=0;i<number-1;i++)
{
for(j=i+1;j<number;j++)
{
if(**(point+i)>**(point+j))//比较之后交换整数地址
{
temp=*(point+i);
*(point+i)=*(point+j);
*(point+j)=temp;
}
}
}
}
编译运行结果:
输入要排序的个数number:3
逐个输入这3个数:1 8 5
-------------------
输出结果:
1 5 8
--------------------------------
Process exited after 6.278 seconds with return value 0
请按任意键继续. . .
今天的分享就到这里了,大家要好好学C语言/C++哟~
写在最后:对于准备学习C/C++编程的小伙伴,如果你想更好的提升你的编程核心能力(内功)不妨从现在开始!
C语言C++编程学习交流圈子,QQ群:763855696【点击进入】
C语言从入门到精通(C语言入门C语言教程C语言零基础C语言基础C语言学习C
整理分享(多年学习的源码、项目实战视频、项目笔记,基础入门教程)
欢迎转行和学习编程的伙伴,利用更多的资料学习成长比自己琢磨更快哦!
编程学习视频分享:


边栏推荐
- Scikit learn -- steps and understanding of machine learning application development
- Pytorch learning notes
- 自贸经济中架起的“隐形桥梁”:国货精品与中国AI力量
- C how to realize simple factory mode
- Arfoundation starts from scratch 8-geospatial API (geospatial) development
- Unity Metaverse(三)、Protobuf & Socket 实现多人在线
- ODOO开发教程之图表
- WDDM学习
- 优炫数据库启动失败,报网络错误
- Force deduction ----- sort odd and even subscripts respectively
猜你喜欢
随机推荐
[wechat applet -- solve the alignment problem of the last line of display:flex. (discontinuous arrangement will be divided into two sides)]
2021-10-11
MySQL many to many relationship, grouping and splicing to query multiple data to one data
WPS insert hyperlink cannot be opened. What should I do if I prompt "unable to open the specified file"!
QT系列---安装
基于注解的三层项目的改造及添加包扫描的方式
Operator operation list of spark
How to install Office2010 installation package? How to install Office2010 installation package on computer
Apache POI实现Excel导入读取数据和写入数据并导出
Arfoundation starts from zero 9-ar anchor
Jackson解析JSON详细教程
Lenovo Savior r7000+ add ssd+ copy and partition the information of the original D disk to the new SSD
小白高薪捷径-Qt开发游戏—贪吃蛇
2021-11-02
TCP three handshakes and four waves
【文件下载】Easyexcel快速上手
Youxuan database failed to start and reported network error
Getting started with arfoundation tutorial 10- plane detection and placement
网安学习-内网安全1
How does WPS take quick screenshots? WPS quick screenshot method


![[untitled]](/img/04/242e85ee8eea5bd6ae8144fc048241.png)






