糯米文學吧

位置:首頁 > 計算機 > C語言

C語言程序改錯習題

C語言5.03K

行動是通向成功的唯一途徑。以下是小編為大家搜索整理的C語言程序改錯習題,希望能給大家帶來幫助!更多精彩內容請及時關注我們應屆畢業生考試網!

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);

}

標籤:習題 改錯 語言