PROGRAM C PERULANGAN - Menginput n buah nilai dan Tentukan nilai tertinggi serta jumlahnya
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitRou-9uX0czlWVyHKoP_j4XstJpEnOtyK663X4DldqWe37qNpionVeoIwhyGPhye1Y_nyh_u8vdmX2djkSKenjRVZ5SjyYmAU93qnjz7siU6Vy4K6Wtq6k2vKno0fSssbqgyGqoZtoZ0/w341-h192/program+c.jpg)
Contoh Kasus :
Masukan : n nilai mahasiswa
Keluaran : nilai tertinggi dan jumlah mahasiswa yang mendapat nilai tertinggi
Test Case
Masukan :
5
70
80
90
90
87
Keluaran :
90
2 Mahasiswa
Program 1
[code hl="1, 4, 7"]
#include<stdio.h>
int main()
{
int byk,max=-1,nilai,count=0;
scanf("%d",&byk);
for (int i=1;i<=byk;i++){
scanf("%d",&nilai);
if (max<nilai){
max=nilai;
count=1;
}
else if(max==nilai){
count++;
}
}
printf("%d nMahasiswa %d",max,count);
return 0;
}
[/code]
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEillNUQm8sdbX2XMzSCRBpmOEkB_JX96WpDfdAO2TtlwAptzEWwZx2NJsJpRrCPXRuXWUkf8cP8dKJwtcTr1Ri8IHorfQZp_RGgitS0uxYsXbFToK7f8uUbgluJGehuJJUP2vnpP5E-NZQ/w466-h214/program+1.png)
Program 2
[code hl="1, 4, 7"]
#include<stdio.h>
void main()
{
int i,n,nilai,tinggi,jumlah;
tinggi=0;
jumlah=0;
scanf("%d", &n);
for(i=1;i<=n;i++){
scanf("%d",&nilai );
if (tinggi<nilai){
tinggi=nilai;
jumlah=1;
}
else if(tinggi == nilai){
jumlah++;
}
}
printf("=================================================n");
printf("%d n%d mahasiswa", tinggi,jumlah);
return 0;
}
[/code]
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh68tQneZeQAVPogvR3A1Ng7cG6-kSJWddtbM1Ukjz0-8teUnSzuoKNDAgs3mwCh0kEPo2kfZXTT6MagzCcpaGYDMsriyp4qrAfJomH5G1kfwMQDSJYFVd8B4SyRj8R7KDGBLDKa9pvKA4/w452-h226/program+2.png)
Program 3
[code hl="1, 4, 7"]
#include <stdio.h>
int main()
{
int n, temp, tinggi = 0, banyak = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%d", &temp);
if (temp >= tinggi)
{
temp != tinggi ? banyak = 1 : banyak++;
tinggi = temp;
}
}
printf("n%dn%d Mahasiswa", tinggi, banyak);
return 0;
}
[/code]
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2Ybvc8kpzOPkA2_dxxGVNMg_sz6efQuixYp-QsTEKUK74SdAiATv17iQAZahfi1ic4O4No2Qm0Vm_R2E6YGrWEmw8CGDhGuu_OER6LpyL9n-3OuJAQcb4luHiBGNJoACXDWoL1Q0E_6Q/w453-h241/program+3.png)
Program 4
[code hl="1, 4, 7"]
#include<stdio.h>
int main(){
int n,i=0,nilai,temp=1,jumlah;
scanf("%d",&n);
while(i<n){
scanf("%d",&nilai);
if (nilai>=temp){
temp = nilai;
jumlah = 1;
if (nilai=temp){
jumlah++;
}
}
i++;
}
printf("%d n",temp);//nilainya
printf("%d Mahasiswa n",jumlah);//banyaknya
return 0;
}
[/code]
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5Y9IKT4Td0xkmV_n9sqiK64gPDSouzp0k7xwCJI0mH8nhPd-XKDwoxtpDFh_yTf1KVavvkq07HY4I9Dpi89iEiQ2nq1IDqJOyduQpmPe9nH_j8FKBcDRFl1ncYwkKOLI7OKcSLAZDGTE/w439-h225/program+4.png)
Program 5
[code hl="1, 4, 7"]
#include<stdio.h>
int main()
{
int N_Input, highest=0, score, sum, i;
printf("N : ");scanf("%d", &N_Input);
for(i=0; i<N_Input; i++)
{
scanf("%d", &score);
if(highest<score)
{
highest=score;
sum=1;
}
else if(highest==score)
{
sum++;
}
}
printf("nNilai tertinggi = %d nMahasiswa %d", highest, sum);
return 0;
}
[/code]
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6uTT5-OyvEe4pb3jgST8ezmsvUKwdwMwz_kwtI6uQUpEnAi-AWuEgCEDJTAqLCUpEWL1nX866IJH6pk8fRiEUYE1MHe7RZrh7_m5dEyyr9hyphenhyphenOBvcCMAv3hJJA6foFav-1qSmwkuF6uLg/w439-h222/program+5.png)
Posting Komentar untuk "PROGRAM C PERULANGAN - Menginput n buah nilai dan Tentukan nilai tertinggi serta jumlahnya"