fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4.  
  5. int i,max1,max2,n[10];
  6. max1 = 0;
  7. max2 = -1;
  8. printf("整数を入力してください\n");
  9.  
  10. for(i = 0;i < 10;i ++){
  11. scanf("%d",&n[i]);
  12. if(n[i] >= max1){
  13. max2 = max1;
  14. max1 = n[i];
  15. }else if(n[i] >= max2){
  16. max2 = n[i];
  17. }
  18. }
  19.  
  20. printf("最大値:%d\n2番目に大きい数:%d\n",max1,max2);
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0s 5288KB
stdin
1
2
3
4
5
6
7
78
9
30
stdout
整数を入力してください
最大値:78
2番目に大きい数:30