当前位置:网站首页>【指针】数组逆序重新存放后并输出
【指针】数组逆序重新存放后并输出
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
边栏推荐
- Web vulnerability - File Inclusion Vulnerability of file operation
- Binary search tree concept
- Intel oneapi - opening a new era of heterogeneity
- SystemVerilog discusses loop loop structure and built-in loop variable I
- 《统计学》第八版贾俊平第二章课后习题及答案总结
- Statistics 8th Edition Jia Junping Chapter 7 Summary of knowledge points and answers to exercises after class
- Proceedingjoinpoint API use
- 浅谈漏洞发现思路
- 内网渗透之内网信息收集(三)
- XSS (cross site scripting attack) for security interview
猜你喜欢
Hackmyvm target series (2) -warrior
Xray and Burp linked Mining
《統計學》第八版賈俊平第七章知識點總結及課後習題答案
1.支付系统
Harmonyos JS demo application development
浅谈漏洞发现思路
Binary search tree concept
Lintcode logo queries the two nearest saplings
Statistics 8th Edition Jia Junping Chapter 7 Summary of knowledge points and answers to exercises after class
Ucos-iii learning records (11) - task management
随机推荐
《英特尔 oneAPI—打开异构新纪元》
SQL注入
Wu Enda's latest interview! Data centric reasons
. Net6: develop modern 3D industrial software based on WPF (2)
flask实现强制登陆
Hackmyvm target series (7) -tron
JDBC transactions, batch processing, and connection pooling (super detailed)
MySQL interview questions (4)
记一次edu,SQL注入实战
A complete collection of papers on text recognition
Statistics 8th Edition Jia Junping Chapter 14 summary of index knowledge points and answers to exercises after class
Tencent map circle
Record once, modify password logic vulnerability actual combat
Statistics 8th Edition Jia Junping Chapter XIII Summary of knowledge points of time series analysis and prediction and answers to exercises after class
Hackmyvm target series (2) -warrior
Only 40% of the articles are original? Here comes the modification method
xray与burp联动 挖掘
【指针】求二维数组中最大元素的值
Network technology related topics
2022华中杯数学建模思路