Pages

Ads 468x60px

Sabtu, 22 Oktober 2011

Program Array dengan C++

#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 komentar:

Posting Komentar