C++——将n个数按输入时顺序的逆序排列,用函数实现。用指针或引用方法处理。

没注释的源代码

#include <iostream>

using namespace std;

void sort(char *p,int m);

int main()

{

int n;

char *p,num[100];

cout<<"please input n:";

cin>>n;

cout<<"please input these numbers:"<<endl;

for(int i=0;i<n;i++)

{

cin>>num[i];

}

p=&num[0];

sort(p,n);

cout<<"now the sequence is:"<<endl;

for(int i=0;i<n;i++)

{

cout<<num[i]<<" ";

}

cout<<endl;

return 0;

}

void sort(char *p,int m)

{

char temp,*p1,*p2;

for(int i=0;i<m/2;i++)

{

p1=p+i;

p2=p+(m-1-i);

temp=*p1;

*p1=*p2;

*p2=temp;

}

}

相关推荐
t***54421 小时前
Clang 编译器在 Orwell Dev-C++ 中的局限性
开发语言·c++
oy_mail21 小时前
QoS质量配置
开发语言·智能路由器·php
oyzz1201 天前
PHP操作redis
开发语言·redis·php
kobesdu1 天前
人形机器人SLAM:技术挑战、算法综述与开源方案
算法·机器人·人形机器人
nashane1 天前
HarmonyOS 6学习:网络能力变化监听与智能提示——告别流量偷跑,打造贴心网络感知应用
开发语言·php·harmony app
yolo_guo1 天前
redis++使用: hmset 与 hmget
c++·redis
凌波粒1 天前
Java 8 “新”特性详解:Lambda、函数式接口、Stream、Optional 与方法引用
java·开发语言·idea
handler011 天前
拒绝权限报错!三分钟掌握 Linux 权限管理
linux·c语言·c++·笔记·学习
拾贰_C1 天前
【Google | Gemini | API | POST】怎么使用Google 的Gemini API (原生版)
开发语言·lua
椰羊~王小美1 天前
随机数概念及算法
算法