zoukankan      html  css  js  c++  java
  • 蓝桥杯——寻找数组中的最大值

    问题描述

      对于给定整数数组a[],寻找其中最大值,并返回下标。
    输入格式
      整数数组a[],数组元素个数小于1等于100。输入数据分作两行:第一行只有一个数,表示数组元素个数;第二行为数组的各个元素。
    输出格式
      输出最大值,及其下标
    样例输入
    3
    3 2 1
    样例输出
    3 0
    答案:
      

    #include <stdio.h>

    #include <string.h>

    int main(int argc, const char * argv[]) {

        int n;

        scanf("%d",&n);

        

        //输入数据

        int a[n];

        int i;

        for (i = 0;i < n;++i) {

            scanf("%d",&a[i]);

        }

        

        //确定最大值

        int max = a[0];

        for (i = 1; i <n;i ++) {

            if (max <a[i]) {

                max = a[i];

            }

        }

        

        //输入数组中的最大值和相应索引

        printf("%d ",max);

        for (i = 0; i < n; i ++) {

            if (max == a[i]) {

                printf("%d",i);

            }

        }

        

        return 0;

    }

  • 相关阅读:
    获取DataGrid数据
    C# 分頁
    TCP 协议
    node fs对象
    ANSI转义码 改变输出的字体颜色
    异步流程控制模式
    node event对象
    js中的异常捕获 try{} catch{}(二)
    node require 文件查找的顺序
    node process全局对象
  • 原文地址:https://www.cnblogs.com/123qw/p/4383911.html
Copyright © 2011-2022 走看看