LISTING PAA3

05.19 Edit This 0 Comments »


#include
#include
#include

void prima (),bsort(),kalimatriks();

main()
{
 start :
 int x;
 clrscr();
 printf ("\n \t Algoritma Brute Force \n");
 printf ("\n ==========================================");
 printf ("\n \t 1. Pencarian Bilangan Prima");
 printf ("\n \t 2. Sorting Bilangan");
 printf ("\n \t 3. Perkalian Matrix");
 printf ("\n \t 4. Exit ");
 printf ("\n ========================================= \n");
 printf ("\n Masukkan Pilihan (1-4) : ");
 scanf ("%d",&x);
 switch(x)
  {
            case 1  : prima ();
                          goto start;
            case 2  : bsort();
                          goto start;
            case 3  : kalimatriks();
                          goto start;
            case 4  : return 0;
            default : clrscr();
                 printf("\n \n \n \n \n \n \t \t \t Anda Salah memasukkan Input");
                          printf("\n \t \t Program Akan Direstart Setelah Anda Menekan Tombol Enter");
                 getch();
                          goto start;
  }
}

void prima ()
{
  int bil,j;
  clrscr();
  printf ("\t \t \t Pencarian Bilangan Prima \n \n \n");
  printf ("Masukkan Data Yang Ingin Diinput: ");
  scanf("%d",&bil);
  for(j=2;j<=bil;j++)
  {
             if ((j%2>0)&&(j%3>0)&&(j%5>0)&&(j%7>0) || (j==2)||(j==3)||(j==5)||(j==7))
             printf ("%i ",j);
  }
  getch();
}

void bsort()
{
  int i,j,temp,n,bil[100];
  clrscr();
  printf ("\t \t \t Sorting Bilangan \n \n \n" );
  printf ("Masukkan jumlah bilangan: " );
  scanf ("%d",&n);
 for(i=0;i
 {
  printf ("Bilangan ke-%d \t: ",i+1);
  scanf ("%d",&bil[i]);
 }
 printf ("\n");
 for(i=0;i
 {
  for(j=n-1;j>i;j--)
  {
            if (bil[i] > bil[j])
   {
             temp = bil[i];
    bil[i] = bil[j];
             bil[j] = temp;
   }
  }
 }
 printf ("Sorting:");
 for(i=0;i
 {
  printf ("%d",bil[i]);
  if (i!= n-1);
  {
            printf (",");
  }
 }
 getch();
}

void kalimatriks()
{
 int i,j,k,temp,ordo,ma[10][10],mb[10][10],mc[10][10];
 clrscr();
 printf ("\t \t \t Perkalian Matrix \n \n \n");
 printf ("Masukkan Ordo Matriks: ");
 scanf ("%d", &ordo);
 printf ("Matriks A: ");
 for(i=0;i
 {
  for(j=0;j
  {
            gotoxy((j+1)*5,i+6);
            scanf ("%d", &ma[i][j]);
  }
 }
 printf ("\n");
 printf ("Matriks B: ");
 for(i=0;i
 {
  for(j=0;j
  {
            gotoxy((j+1)*5,i+8+ordo);
            scanf ("%d", &mb[i][j]);
  }
 }
 for(i=0;i
 {
  for(j=0;j
  {
            temp = 0;
            for(k=0;k
            {
             temp += ma[i][k] * mb[k][j];
            }
            mc[i][j] = temp;
  }
 }
 printf ("\n \n");
 printf ("Hasil Matriks A * Matriks B: ");
 for(i=0;i
 {
  for(j=0;j
  {
            gotoxy((j+1)*5,i+11+ordo*2);
            printf ("%d",mc[i][j]);
  }
 }
 getch();
}

OUTPUT: 





0 komentar: