就业数据资源平台
当前位置:首页 > C语言程序设计
全国计算机等级考试C语言考试程序改错题(3)

在考生文件夹下,给定程序MODI.C的功能是:


求一维数组a中的最大元素及其下标。


例如,当一维数组a中的元素为:1,4,2,7,3,12,5,34,5,9,


程序的输出应为:The max is: 34,pos is: 7 。


 


  #include


  #include


  void main()


  {


     int a[10]={1,4,2,7,3,12,5,34,5,9},i,max,pos;


     max = a[0];


     pos = 0;


     for ( i=1; i<10; i++)


     /************found************/








if(max


      if (max > a[i])


      {


       max = a[i];


  /************found************/








pos=i;


       i = pos;


      }


     printf("The max is: %d ,pos is: %d\n", max , pos);


}

就业数据资源平台