Manipulasi Data




//source code untuk memanipulasi data

#include

#include

#include



int i,data[255],elemen,counter;



void tambah(int nilai_elemen) //penambahan data

{

 data[counter]=nilai_elemen;

 counter++;

 printf("Data masuk\n");

}



void tampil()  //menampilkan data

{

 for(i=0;imax)

   max=data[i];

 }

 return max;

}



int total()

{

 int jum=0;

 for(i=0;imax2)

  {

   if(data[i]!=max) max2=data[i];

  }

 }

 return max2;

}



void main()

{

 int pilih,nilai;

 counter=0;



 while(pilih<10)

 {



  system("cls");



  garis();

  printf("%c                  %c\n",176,176);

  printf("%c MANIPULASI DATA  %c\n",176,176);

  printf("%c                  %c\n",176,176);

  garis();

  printf("%c               %c\n",176,176);

  printf("%c  1.Tambah Data  %c\n",176,176);

  printf("%c  2.Tampilkan Data %c\n",176,176);

  printf("%c  3.Edit Data  %c\n",176,176);

  printf("%c  4.Hapus Data  %c\n",176,176);

  printf("%c  5.Nilai Minimum %c\n",176,176);

  printf("%c  6.Nilai Maksimum %c\n",176,176);

  printf("%c  7.Maksimum ke - 2 %c\n",176,176);

  printf("%c  8.Total         %c\n",176,176);

  printf("%c  9.Rata - rata  %c\n",176,176);

  printf("%c 10.Quit          %c\n",176,176);

  printf("%c               %c\n",176,176);

  garis();

  printf("Masukkan pilihan : ");scanf("%i",&pilih);



  switch(pilih)

  {

   case 1: printf("Masukkan data : ");scanf("%i",&nilai);

     tambah(nilai);

     break;

 

   case 2: tampil();

     break;

 

   case 3: printf("Data ke : ");scanf("%i",&elemen);

     printf("Masukkan nilai : ");scanf("%i",&nilai);

     data[elemen-1]=nilai;

     break;



   case 4: printf("Data ke : ");scanf("%i",&elemen);

     data[elemen-1]=NULL;

     defrag();

     printf("\nData ke %i sudah dihapus...\n",elemen);

     break;



   case 5: printf("Nilai minimum : %i",minimum());

     break;



   case 6: printf("Nilai maksimum : %i",maksimum());

     break;



   case 7: printf("Nilai maksimum ke - 2 : %i",maks2());

     break;



   case 8: printf("Total : %i",total());

     break;



   case 9: printf("Nilai rata - rata : %.3f",mean());

     break;



   case 10:

     break;

  }

  getch();

 }





0 comments:

Post a Comment