行動是通向成功的唯一途徑。以下是小編爲大家搜索整理的C語言程序改錯習題,希望能給大家帶來幫助!更多精彩內容請及時關注我們應屆畢業生考試網!
在考生文件夾下,給定程序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: %dn", max , pos);
}