实现数组的反向输出

/*******************对数组元素的值进行反向输出实现******************************/

#include<stdio.h>

#define MAX_SIZE 10

void Chang_elem_arr(int *x,int n);     //将数组元素进行反向

void Show_elem_arr(int *x);             //将反向的数组打印到屏幕上

int main()

{

int arr[MAX_SIZE]={1,4,5,4,82,45,19,9,1,3};

Chang_elem_arr(arr,MAX_SIZE);

Show_elem_arr(arr);

return 0;

}

void Chang_elem_arr(int *x,int n)    //实现对提供的数组进行反向输出

{

int temp,*p,*q,m;

m=n/2;       //记录数组中间部分的位置

p=x;    //指向数组的第一个元素

q=x+n-1;     // 指向数组的最后一个元素

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

{

temp=*p;

*p=*q;

*q=temp;

p++;

q--;

}

}

void Show_elem_arr(int *x)

{

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

{

printf("输出的数为:%d\n",x[i]);

}

}

由于是处于刚学习阶段,写的不好望见谅,只是想通过这种方式加深自己的理解。

时间: 2024-08-07 00:18:05

实现数组的反向输出的相关文章

反向输出用户录入的字符串

class Program { static void Main(string[] args) { Console.WriteLine("请录入要反向输出的字符或其它"); //将用户输入的字符串,放入字符数组中 char[] str = Console.ReadLine().ToCharArray(); //将素组中的元素反转 Array.Reverse(str); //遍历数组 foreach (var c in str) { Console.Write(c); } Console

反向输出字符串

//反向输出字符串 public class SwitchOne { public static void main(String[] args) { String aa= "hello"; //字符串 String [] bb=new String[aa.length()];//定义同等长度数组 for(int i=1;i<=bb.length;i++){ bb[i-1]=aa.substring(i-1,i); //截取字符串的每一个字符,并赋值给数组元素 System.ou

【C++】输入并反向输出字符串

<pre name="code" class="cpp">// 反向输出字符串 #include<iostream> #include<string.h> using namespace std; void f(char p[]); int main() { char s[50]; cout<<"请输入一个字符串: "; cin>>s; f(s); cout<<"反

1-3-13:反向输出一个三位数

描述 将一个三位数反向输出. 输入一个三位数n.输出反向输出n.样例输入 100 样例输出 001 1 #include<stdio.h> 2 #include<math.h> 3 int main() 4 { 5 char a[3]; 6 int i; 7 scanf("%s",&a); 8 for(i=2;i>=0;i--) 9 printf("%d",a[i]-'0'); 10 printf("\n")

九九乘方表/数组排序/反向输出字符串

大家好: 今天在逛百度的时候有位芝麻问了个问题,感觉他是一个初学者!把他的代码添枝加叶了一下成了下面几个程序!大家共勉一下吧! 共 五 个方法: <span style="font-size: 18px;">//格式4 * 3 * 2 * 1 = 24</span> <span style="font-size: 18px;">//</span><span style="font-size: 18px;

定义一个含有30个整型元素的数组,按顺序分别赋予从2开始的偶数;然后按顺序每五个数求出一个平均值,放在另一个数组中并输出

<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript"> //定义一个含有30个整型元素的数组,按顺序分别赋予从2开始的偶数:然后按顺序每五个数求出一个平均值,放在另一个数组中并输出. var arr = []; var NewArr = []

4.19递归反向输出字符串

Q:编写一个递归函数,实现将输入的任意长度字符串反向输出的功能. #include <iostream> #include<cstdio> using namespace std; print() { char a; cin>>a; if(a!='#') print();//输入字符不是结束标志#,则递归调用print() if(a!='#') cout<<a;//输入字符时不输出# } int main() { printf("input a s

rev 反向输出文件内容

1.命令功能 rev 按行反向输出文件内容 2.语法格式 rev  file 3.使用范例 [[email protected] ~]# echo {a..k} >> test [[email protected] ~]# cat test a b c d e f g h i j k [[email protected] ~]# rev test k j i h g f e d c b a [[email protected] ~]# echo {a..k} |rev k j i h g f

js数组乱序输出 数组乱序排列

网上看的数组乱序输出,要么不合实际,要么代码繁琐.自己试了下,希望能给大家带来帮助. 重要思想也是Math.random*arr.length随机下标,然后删除取到的元素,继续随机下标. //将数组乱序输出 var arr = [1,2,3,4,5,6,7,8,9,10]; var newArr = []; for(var i=0; i<arr.length; i++){ var index = Math.floor(Math.random()*arr.length);//随机下标 newArr