zoukankan      html  css  js  c++  java
  • 倒序--逆序=3 rwkj 1271

    C语言:递归函数3(数组倒序)

    时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte
    总提交:786            测试通过:347

    描述

     

    输入多个整数,以0结束,将这些整数逆序后输出。

    要求:使用递归函数将数组倒序,在main中调用递归函数。

    输入

    多个整数,最后为0。

    输出

    逆序后的这些整数。

    样例输入

    1 2 5 4 0
    1 2 3 4 5 6 7 8 9 0

    样例输出

    4 5 2 1
    9 8 7 6 5 4 3 2 1

    提示

     

    注意:每个数后面有一个空格。

    #include <stdio.h>
    void f(int a[],int n)
    {    int i,t;
        for ( i=0; i<n/2; i++) 
        {   t=a[i]; a[i]=a[n-1-i]; a[n-1-i]=t;    }
    }
    int main()
    {    int a[100],n,i;
        while (scanf("%d",&a[0])!=EOF)
        {   
         n=1;
            while(  scanf("%d",&a[n]) )
            {    if (a[n]==0) break;
                n++;
            }   
            f(a,n);
            for (i=0; i<n; i++) printf("%d ",a[i]);
            printf("
    ");
        }
    } 
    View Code

    #include <stdio.h>
    void f(int a[],int n)
    { int i,t;
    for ( i=0; i<n/2; i++)
    { t=a[i]; a[i]=a[n-1-i]; a[n-1-i]=t; }
    }
    int main()
    { int a[100],n,i;
    while (scanf("%d",&a[0])!=EOF)
    {
    n=1;
    while( scanf("%d",&a[n]) )
    { if (a[n]==0) break;
    n++;
    }
    f(a,n);
    for (i=0; i<n; i++) printf("%d ",a[i]);
    printf(" ");
    }
    }

  • 相关阅读:
    8/30 sql脚本
    navicat批量添加uuid去重
    循环向JsonArray添加对象
    java String字符串去除()里的内容
    工厂模式
    Thymeleaf学习
    SSH开发常用常见的src下建的包名
    04jQuery操作03
    04jQuery筛选jquery对象02
    04jQuery筛选jquery对象01
  • 原文地址:https://www.cnblogs.com/2014acm/p/3901329.html
Copyright © 2011-2022 走看看