正在加载图片...
例8-8将数组元素逆序存放#include<stdio.h>Enter n:10Enter10 integers:10 9 8 7 6 5 4 32 1int main(void)12345678910(int i, a[10],n;void reverse(int p[ ], int n);printf("Enter n: ");scanf("%d", &n);printf("Enter %d integers:", n);for(i= 0; i< n; i++)void reverse(int p[ ], int n)scanf("%d", &a[i]); inti,j, t;reverse(a, n);for(i= 0; i< n; i++)for(i=0, j=n-1; i<j; i++, j--)(printf("%d\t", a[i]);t = p[]; p[i] = p]; p] = t;return 0;117#include <stdio.h> int main(void) { int i, a[10],n; void reverse(int p[ ], int n); printf("Enter n: "); scanf("%d", &n); printf("Enter %d integers: ", n); for(i = 0; i < n; i++) scanf("%d", &a[i]); reverse(a, n); for(i = 0; i < n; i++) printf("%d\t", a[i]); return 0; } 例8-8 将数组元素逆序存放 void reverse(int p[ ], int n) { int i, j, t; for(i=0, j=n-1; i<j; i++, j-){ t = p[i]; p[i] = p[j]; p[j] = t; } } Enter n:10 Enter 10 integers: 10 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有