#include<iostream.h>
#include<conio.h>
void main(){
//deklarasi array
float angka['a'],a,total=0,rata;
cout<<"masukkan jumlah elemen array: ";
cin>>a;
//meminta nilai array
for(int i=0;i<a;i++){
cout<<"masukkan nilai ke ["<<i+1<<"]= ";
cin>>angka[i];
}
cout<<endl;
//menampilkan nilai array
cout<<"nilai array yang Anda masukkan :"<<endl;
int max=0,min=1000;
for(int x=0;x<a;x++){
cout<<"nilai indeks ke ["<<x<<"]= "<<angka[x];
total=total+angka[x];
//max,min,total
if(max<angka[x]){
max=angka[x];
}
if(min>angka[x]){
min=angka[x];
}
cout<<endl;
}
cout<<endl;
//nilai terbesar
cout<<"nilai terbesar: "<<max<<endl;
//nilai terkecil
cout<<"nilai terkecil: "<<min<<endl;
//total nilai
cout<<"total: "<<total<<endl;
//rata-rata
rata= total/a;
cout<<"rata-rata= "<<total<<"/"<<a<<": "<<rata;
getch();
}
#include<conio.h>
void main(){
//deklarasi array
float angka['a'],a,total=0,rata;
cout<<"masukkan jumlah elemen array: ";
cin>>a;
//meminta nilai array
for(int i=0;i<a;i++){
cout<<"masukkan nilai ke ["<<i+1<<"]= ";
cin>>angka[i];
}
cout<<endl;
//menampilkan nilai array
cout<<"nilai array yang Anda masukkan :"<<endl;
int max=0,min=1000;
for(int x=0;x<a;x++){
cout<<"nilai indeks ke ["<<x<<"]= "<<angka[x];
total=total+angka[x];
//max,min,total
if(max<angka[x]){
max=angka[x];
}
if(min>angka[x]){
min=angka[x];
}
cout<<endl;
}
cout<<endl;
//nilai terbesar
cout<<"nilai terbesar: "<<max<<endl;
//nilai terkecil
cout<<"nilai terkecil: "<<min<<endl;
//total nilai
cout<<"total: "<<total<<endl;
//rata-rata
rata= total/a;
cout<<"rata-rata= "<<total<<"/"<<a<<": "<<rata;
getch();
}
ternyata langsung bisa di coba,,,
ReplyDeletemakasih infonya
mantap bng
ReplyDeleteklo blh nanya bng tau situs yg buat belajar c++ ga bng? kyk topcoder sama codeacademy tapi yg berbahasa indonesia hehe
ReplyDelete