//昇順になっているか否かを確認 void main(){ int x[5]; // 箱が5個できる. x[0], x[1], x[2], x[3], x[4] x[0] = 6; x[1] = 43; x[2] = 12; x[3] = 78; x[4] = 8; if( x[0]<=x[1] && x[1]<=x[2] && x[2]<=x[3] && x[3]<=x[4] ){ printf("ok\n"); } else { printf("ng\n"); } printf("%d %d %d %d %d\n", x[0], x[1], ...); } ---- //昇順になっているか否かを確認 void main(){ int x[5]; // 箱が5個できる. x[0], x[1], x[2], x[3], x[4] int i, cnt; x[0] = 6; x[1] = 43; x[2] = 12; x[3] = 78; x[4] = 8; cnt = 0; for(i=0; i<5-1; i++){ if( x[i] <= x[i+1] ){ cnt ++; } } if( cnt == 4 ){ printf("ok\n"); } else { printf("ng\n"); } printf("%d %d %d %d %d\n", x[0], x[1], ...); } ---- int x=5, y=7, a, b, c, d, e, f, g; // xとy を交換 !!! a = x; x = y; y = a; printf("%d %d", x, y); ---- //昇順に変更 void main(){ int x[5]; // 箱が5個できる. x[0], x[1], x[2], x[3], x[4] int i, cnt; x[0] = 6; ... x[4] = 8; do{ if( x[0] > x[1] ){ a = x[0]; x[0] = x[1]; x[1] = a; } if( x[1] > x[2] ){ a = x[1]; x[1] = x[2]; x[2] = a; } if( x[2] > x[3] ){ a = x[2]; x[2] = x[3]; x[3] = a; } if( x[3] > x[4] ){ a = x[3]; x[3] = x[4]; x[4] = a; } cnt = 0; for(i=0; i<5-1; i++){ if( x[i] <= x[i+1] ){ cnt ++; } } } while( cnt < 4 ); printf("%d %d %d %d %d\n", x[0], x[1], ...); } ---- //昇順に変更 void main(){ int x[5]; // 箱が5個できる. x[0], x[1], x[2], x[3], x[4] int i, cnt, a; x[0] = 6; ... x[4] = 8; do{ for(i=0; i<5-1; i++){ if( x[i] > x[i+1] ){ a = x[i]; x[i] = x[i+1]; x[i+1] = a; } } cnt = 0; for(i=0; i<5-1; i++){ if( x[i] <= x[i+1] ){ cnt ++; } } } while( cnt < 4 ); printf("%d %d %d %d %d\n", x[0], x[1], ...); }