28
Okt
08

contoh program menggunakan array dengan C++

Mencari nilai tertinggi, nilai terendah, rata-rata

#include <iostream.h>

#include <stdio.h>

#include <conio.h>

#include <math.h>

void input(int x[],int n)

{

for (int i=1;i<=n;i++)

{cout<<”Masukan Nilai “<<i<<” : “;cin>>x[i];}

}

void tinggi(int x[],int n)

{

int max,min;

max = x[1];

min = x[1];

for (int i=2;i<=n;i++)

{

if (max < x[i])

max = x[i];

if (min > x[i])

min = x[i];

}

cout<<”\nNilai tertinggi = “<<max<<”\n”;

cout<<”Nilai terendah = “<<min<<”\n”;

}

double rata(int x[],int n)

{

double a,b;

a = 0;

for (int i=1;i<=n;i++)

{

a = a + x[i];

}

b = a/n;

cout<<”Rata-Rata : “<<a<<”/”<<n<<” = “<<b;

}

void main()

{

int p[50],N;

cout<<”Banyaknya Data : “;cin>>N;

cout<<endl;

input(p,N);

tinggi(p,N);

rata (p,N);

getch();

}



0 Responses to “contoh program menggunakan array dengan C++”



  1. Tinggalkan sebuah Komentar

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Logout / Ubah )

Twitter picture

You are commenting using your Twitter account. Logout / Ubah )

Facebook photo

You are commenting using your Facebook account. Logout / Ubah )

Google+ photo

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s


Ikuti

Get every new post delivered to your Inbox.

%d bloggers like this: