下の2つのfor文の中でc=a[i+1]がfor文の中に入っている場合とそうでない場合に結果が異なるのは何故ですか?
lang
1コードint max(int a[] , int s , int e){ 2 int i; 3 int c = 0; 4 for(i = s-1; i < e-1; i++){ 5 if(a[i] >= a[i+1]){ 6 a[i+1] = a[i]; 7 } 8 else{ a[i+1] = a[i+1]; 9 } 10 c = a[i+1]; 11 12 } 13 return c; 14} 15 16int max_index(int a[] , int s , int e){ 17 int i; 18 int c = 0; 19 for(i = s-1; i < e-1; i++){ 20 if(a[i] >= a[i+1]){ 21 a[i+1] = a[i]; 22 } 23 else{ a[i+1] = a[i+1]; 24 } 25} 26 c = a[i+1]; 27 return c; 28}
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。