Angga_Wahyu

C++ Program to print 2 Score Maximum

Nov 28th, 2019
783
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. main(){
  5.     int a[10], max=0, max2=0, panjang;
  6.    
  7.     cout<<"Panjang Array : ";
  8.     cin>>panjang;
  9.     for(int i=0; i<panjang; i++){
  10.         cout<<"Array ke-"<<i<<" : ";
  11.         cin>>a[i];
  12.        
  13.         if(a[i]>max)
  14.         {
  15.             max2=max;
  16.             max=a[i];
  17.         }
  18.         else if(a[i]>max2){
  19.             max2=a[i];
  20.         }
  21.     }
  22.     cout<<"Nilai Max ke-1 : "<<max<<endl;
  23.     cout<<"Nilai Max ke-2 : "<<max2;
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment