Skip to content

Instantly share code, notes, and snippets.

@Humayung
Created September 30, 2019 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Humayung/b6f25839a76d9768e6c7bd682b553e94 to your computer and use it in GitHub Desktop.
Save Humayung/b6f25839a76d9768e6c7bd682b553e94 to your computer and use it in GitHub Desktop.
Mencari nilai modus dalam sebuah array integer
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cout << "Program mencari elemen terbesar dari sebuah larik integer"<<endl;
cout << "Masukkan panjang array (N)"<<endl;
cin >> n;
int a[n];
cout << "Masukkan elemen array (Pisah dengan Enter)"<<endl;
// Katakan nilai terbesar adalah yang
// paling kecil yang mungkin dalam range INTEGER
int max = INT_MIN;
// Lakukan perulangan untuk mendapatkan elemen-elemen
// array sekaligus mencari nilai terbesar
for(int i = 0;i < n; i++){
cin >> a[i];
// Ternary operasi sebagai pengganti IF
max = a[i] > max ? a[i] : max;
}
printf("Nilai terbesar dari larik tersebut adalah %d", max);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment