10.13-3 指针与一维数组相关运算

来源:互联网 发布:高要网络问政平台 编辑:程序博客网 时间:2024/06/07 10:14

【输出数组最大值】

#include<stdio.h>#define SIZE 5void max(  int *source,int *end);int main(){     int source[SIZE] = { 1,2,3,4,5 };     printf("the max of the arry:\n");     max(source, source + SIZE);    getchar();    getchar();    return 0;}void max(  int *source, int *end){    int max = *source;    while (source < end)    {        if (max < *source)        {            max = *source;            source++;        }        else        {            source++;        }    }    printf("%d ", max);}

【数组逆序输出】

#include<stdio.h>#define SIZE 5void Reverse_Arry( double *source, double *arry, double *end);int main(){    double source[SIZE] = { 1.1,2.2,3.3,4.4,5.5 };    double arry[SIZE] = { 0 };    Reverse_Arry(source, arry, source + SIZE);    for (int i = 0; i < SIZE; i++)        printf("%8.3lf  ", arry[i]);    putchar('\n');    getchar();    getchar();    return 0;}void Reverse_Arry(double *source, double *arry, double *end){    while (source < end)    {        *(arry + (SIZE-1)) = *(source);        source++;        arry--;    }}