C++ Nilai Terbesar

#include<iostream>
#include<conio.h>
main(){
int a[100],n,c,s,big1,big2;

cout<<" Masukan jumlah data : ";
cin>>n;
 for (c=1;c<=n;c++)
    { cout<<"Nilai ke-"<<c<<" = ";
      cin>>a[c];
    }
big1=a[1];
 for (c=1;c<=n;c++)
    {if(a[c]>big1)
    {big1=a[c];
    }}
big2 = a[1];
 for (c=1;c<=n;c++)
    {if ((a[c]>big2)&&(a[c]!=big1))
    {big2=a[c];
    }}
 cout<<"Nilai terbesar ke-1 = "<<big1<<endl;
 cout<<"Nilai terbesar ke-2 = "<<big2;
 getch();
 return 0;
}

0 Response to "C++ Nilai Terbesar"

Posting Komentar