c语言找到数组中最大的成员和下标

来源:互联网 发布:91kge网络在线ktv 编辑:程序博客网 时间:2024/05/16 07:19

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define  M 10
int main(int argc, const char * argv[])
{
 
    
    //1:找出数组arr中值最大的数组成员,打印值和下标(比较和查找)
    int i;
    int j;
    int max;
 
    int t;
    int a[M]={};
    for (i=0; i<M; i++)
    {
        a[i]=rand()%100;
        printf("%d ",a[i]);
    }
    for (i=0,max=a[0]; i<M; i++) {
        if(a[i]>max)
        {
            max=a[i];
            a[i]=a[i];
            t=i;
    
        }
    }
    

    printf("\n max = %d\n",max);
    
    printf("\n t = %d\n",t);
    
    
    return 0;
}
0 0
原创粉丝点击