当前位置:网站首页>【指针】数组逆序重新存放后并输出
【指针】数组逆序重新存放后并输出
2022-07-06 09:24:00 【|光|】
要求
编写程序,输入n个整数存入一维数组,再按逆序重新存放后再输出。(用指针实现)
代码
#include<stdio.h>
/* * 该函数用来输入一维整数数组,输入的数据存放在形参a数组中 * 输入的数据以0作为结束标志,0不存入数组也不计入输入数据的总数 * 返回值为输入数据的个数 */
int input(int a[])
{
int n=0;
int b = 0;
do
{
scanf("%d",&b);
if(b == 0)
break;
else
{
a[n] = b;
n++;
}
}
while(b != 0);
return n;
}
/* * 该函数用来实现计算形参数组a的逆序存放 * n为a数组中的整数个数 */
void fun(int a[],int n)
{
int b[n],c = 0;
for(int i = n-1;i>=0;i--)
{
b[c] = a[i];
c++;
}
for(int i = 0;i<n;i++)
{
a[i] = b[i];
}
}
main函数
int main()
{
int a[200],n;
n=input(a);
fun(a,n);
for(int i=0;i<n;i++)
printf("%d ",a[i]);
return 0;
}
测试
测试输入
1 3 5 7 0
输出
7 5 3 1
边栏推荐
- Intranet information collection of Intranet penetration (4)
- MySQL learning notes (stage 1)
- XSS之冷门事件
- Captcha killer verification code identification plug-in
- Statistics 8th Edition Jia Junping Chapter IX summary of knowledge points of classified data analysis and answers to exercises after class
- Hackmyvm target series (4) -vulny
- Binary search tree concept
- Spot gold prices rose amid volatility, and the rise in U.S. prices is likely to become the key to the future
- C language file operation
- Résumé des points de connaissance et des réponses aux exercices après la classe du chapitre 7 de Jia junping dans la huitième édition des statistiques
猜你喜欢
网络层—简单的arp断网
小程序web抓包-fiddler
JDBC事务、批处理以及连接池(超详细)
内网渗透之内网信息收集(五)
Attack and defense world misc practice area (simplerar, base64stego, no matter how high your Kung Fu is, you are afraid of kitchen knives)
Detailed explanation of network foundation routing
《统计学》第八版贾俊平第十四章指数知识点总结及课后习题答案
New version of postman flows [introductory teaching chapter 01 send request]
线程的实现方式总结
《统计学》第八版贾俊平第四章总结及课后习题答案
随机推荐
1.支付系统
《统计学》第八版贾俊平第十三章时间序列分析和预测知识点总结及课后习题答案
Markdown font color editing teaching
浙大版《C语言程序设计实验与习题指导(第3版)》题目集
Intel oneapi - opening a new era of heterogeneity
关于超星脚本出现乱码问题
Spot gold prices rose amid volatility, and the rise in U.S. prices is likely to become the key to the future
MSF generate payload Encyclopedia
Statistics 8th Edition Jia Junping Chapter 7 Summary of knowledge points and answers to exercises after class
Hackmyvm target series (2) -warrior
7-14 error ticket (PTA program design)
SQL injection
Only 40% of the articles are original? Here comes the modification method
《统计学》第八版贾俊平第二章课后习题及答案总结
Harmonyos JS demo application development
我的第一篇博客
Record an edu, SQL injection practice
JDBC看这篇就够了
Hackmyvm target series (4) -vulny
《统计学》第八版贾俊平第三章课后习题及答案总结