Program Mencari Max dengan C++

Tuesday, March 29, 2011 5:37 PM by Computer and Programming
#include <conio>
#include <iostream>

main()
{

int A[100];
int max,batas,jml,pilih;

menu:
cout<<"menu;";
cout<<"\n1. jumlah";
cout<<"\n2. max";
cout<<"\nmasukkan pilihan = ";
cin>>pilih;

if(pilih==1)
{
cout<<"\nmasukkan batas: ";
cin>>batas;
jml=0;
for (int x=0;x<batas;x++){
cout<<"masukkan data "<<(x+1)<<" = ";
cin>>A[x];
jml=jml+A[x];}
cout<<"jumlah = "<<jml;
}

else if(pilih==2)
{
cout<<"\nmasukkan batas: ";
cin>>batas;
for (int x=0;x<batas;x++){
cout<<"masukkan data "<<(x+1)<<" = ";
cin>>A[x];
}
for (int y=0;y<batas;y++){
if (A[y]>max){
max=A[y];
}
}
cout<<"max = "<<max;
}
getch();
}

0 Response to "Program Mencari Max dengan C++"

Post a Comment