Blue Bridge Cup--look for the maximum value in the array

Source: Internet
Author: User

Problem description

For a given array of integers a[], look for the maximum value and return the subscript. Input format integer array a[], the number of array elements is less than 1 equals 100. The input data is divided into two lines: the first line has only one number, which indicates the number of array elements, and the elements of the second behavior array. Output format output maximum value, and its subscript sample input 33 2 1 sample Output 3 0 Answer:

#include <stdio.h>

#include <string.h>

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

int n;

scanf ("%d", &n);

Input data

int a[n];

int i;

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

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

}

Determining the maximum Value

int max = a[0];

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

if (max <a[i]) {

max = A[i];

}

}

The maximum value in the input array and the corresponding index

printf ("%d", max);

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

if (max = = A[i]) {

printf ("%d", I);

}

}

return 0;

}

Blue Bridge Cup--look for the maximum value in the array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.