5-1 求最大值及其下标 (20分)

来源:互联网 发布:java replace first 编辑:程序博客网 时间:2024/06/07 04:48

求最大值及其下标(https://pta.patest.cn/pta/test/6427/exam/4/question/93517)

题目判定

#include<stdio.h>int main(){    int n, i, max, j = 0;    scanf_s("%d", &n);    int str[10];    for (i = 0; i < n; i++)    {        scanf_s("%d", &str[i]);        //printf(" "); 格式有误    }    max = str[0];    for (i = 1; i < n; i++)    {        if (max < str[i])        {            max = str[i];            j = i;        }    }    printf("%d %d", max, j);}
原创粉丝点击