Sabtu, 06 Oktober 2012

Array (Input,edit,delete,cari,tampil)


#include <iostream.h>
#include <conio.h>

void main () {
{
int nilai[100],cari,a,b,hapus;
cout<<"Nilai yang di inginkan :";cin>>a;
cout<<"\nArray \n";
for (b=0;b<a;b++){
cout<<"Nilai : ";cin>>nilai[b];}
cout<<"\nOutput Dari Nilai: \n";
for(b=0;b<a;b++){
   cout<<"\nNilai :"<<nilai[b];}
   cout<<"\n\n================================== ";

cout<<"\n\nEdit Data Yang Lama";
cout<<"\n\nData lama :";
for(a=0;a<b;a++){
cout<<"\nNilai: ";cin>>nilai[a];}
cout<<"\nData Yang Baru : \n";
   nilai[0]=6;
nilai[1]=4;
nilai[2]=9;
nilai[3]=2;
for(a=0;a<b;a++){cout<<" "<<nilai[a];}
      cout<<"\n\n================================== ";

   cout<<"\n\nHapus Data";
cout<<"\n\Data Yang Lama\n";
for(a=0;a<b;a++)
{cout<<" "<<nilai[a];}
cout<<" \nData Yang Dihapus :"; cin>>hapus;
cout<<"Data Baru :\n";
   for (a=hapus-1;a<b-1;a++){nilai[a]=nilai[a+1];}
   for (a=0;a<b-1;a++){cout<<" "<<nilai[a];}
cout<<"\n\ncari Data :";cin>>cari;
for (int a=0;a<b;a++)
{if (nilai[a]==cari)
{cout<<"\n\nNilai Index pada "<<a;
break;
   }
}
}

getch();}

0 komentar:

Posting Komentar