問題一覧
お問い合わせ
light_mode
dark_mode
最大値と最小値 (C)
問題
n 個の整数を読み込みながら、if 文で最大値と最小値を更新していくプログラムです。
入力例
6 15 -3 42 8 0 27
出力例
最大値: 42 最小値: -3
スタート
残り時間:
00:00
速度:
0
文字/分
参照コード
コピーはできません。自分でタイピングしてください。
#include <stdio.h> int main(int argc, const char *argv[]) { int n, x; scanf("%d", &n); scanf("%d", &x); int max = x, min = x; for (int i = 1; i < n; i++) { scanf("%d", &x); if (x > max) { max = x; } if (x < min) { min = x; } } printf("最大値: %d\n", max); printf("最小値: %d\n", min); return 0; }
入力エリア
コンパイル&実行
3