Jan 11, 2012

Array C++

Contoh Array dalam C++

#include<iostream.h>
main ()
{int x[5],i,j,max,min;
for (i=0;i<=4;i++)
{cout<<"input data x yg ke"<<i<<" ";cin>>x[i];
}

cout<<"Data X yang diinputkan"<<endl;
j=0;
max=0;
min=32000;
for (i=0;i<=4;i++)
{cout<<x[i]<<endl;
j=j+x[i];

if (x[i]>max) max=x[i];
if (x[i]<min) min=x[i];
}
cout <<"Jumlah      :"<<j<<endl;
cout <<"Rata-rata :"<<j/(i+1)<<endl;
cout <<"Tertinggi :"<<max<<endl;
cout <<"Terendah  :"<<min<<endl;
return (0);
}

Share on Facebook
Share on Twitter
Share on Google+
Tags :

Related : Array C++