zoukankan      html  css  js  c++  java
  • 将一个数组中的值按逆序重新存放

    #include <stdio.h>
    int main()
    {
        int i,a[100],number,mid,temp1,temp2;
        printf("How many numbers do you want to enter? ");
        scanf("%d",&number);//确定数组长度
        
        printf("Please input array: ");
        for(i=0;i<number;i++)
        scanf("%d",&a[i]);
        
        printf("your array is: ");                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
        for(i=0;i<number;i++)
        printf("%5d",a[i]);
        printf(" ");
        
        if(number%2==1)//输入奇数位序列
        {
            mid=(number-1)/2;
            for(i=0;i<=mid;i++)
            {
                temp1=a[mid-i];
                a[mid-i]=a[mid+i];
                a[mid+i]=temp1;
            }
            
         }
        
         else//输入偶数位序列
         {
             for(i=0;i<=number/2-1;i++)
             {
                 temp2=a[i];
                 a[i]=a[number-(i+1)];
                 a[number-(i+1)]=temp2;
              }
         }
         printf("逆序排序后的数组为: ");
         for(i=0;i<number;i++)
         printf("%5d",a[i]);
        return 0;
    }

  • 相关阅读:
    js将图片转换为base64
    java 后台将base64字符串保存为图片
    mysql truncate drop delete的区别
    java的反射机制
    mysql的三大范式
    EasyUi datagrid鼠标的悬停效果
    SimpleDateFormat关于时间类的一些常用处理
    mysql修改表字段属性类型
    Spring Boot 之注解@Component @ConfigurationProperties(prefix = "sms")
    tomcat如何修改发布目录
  • 原文地址:https://www.cnblogs.com/LiQingXin/p/12996522.html
Copyright © 2011-2022 走看看