Advertisement
Ciro_meneses

Lê 100 numeros e imprime o 1º maior e o 2º maior

Nov 16th, 2015
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. #define TAM 100
  8. #define NUMERO_MIN -9999
  9.  
  10. int main() {
  11.   int i, n[TAM], maior1 = NUMERO_MIN, maior2 = NUMERO_MIN;
  12.  
  13.  
  14.  
  15.   for (i = 0; i < TAM; i++) {
  16.     cout << "n[" << i << "]: ";
  17.     cin >> n[i];
  18.  
  19.     if (n[i] > maior1) {
  20.       maior2 = maior1;
  21.       maior1 = n[i];
  22.     }
  23.     else if (n[i] > maior2 && n[i] != maior1) {
  24.       maior2 = n[i];
  25.     }
  26.   }
  27.  
  28.   cout << "1 maior: " << maior1 << endl;
  29.   cout << "2 maior: " << maior2 << endl;
  30.  
  31.   system("pause");
  32.   return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement