IJUL'S BLOG

Contoh soal C++

 catatan kuliahq:

 * membuat menu :
    1. mencari hasil kuadrat dari bilangan-bilangan ganjil yang merupakan
       kelipatan 3 (mulai dari x sampai y)
   2. mencari hasil jumlah,kurang,bagi,kali dari deret diatas */

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

void main()
{
    int i,x,y,kuadrat,pil,jum;
   char lagi;

   lagi='y';
   jum=0;
   while ((lagi=='y') || (lagi=='Y'))
   {
       clrscr();
      cout<<"###############################################################"<<endl;
      cout<<"#                                                             #"<<endl;
      cout<<"#                 M.E.N.U    P.I.L.I.H.A.N                    #"<<endl;
      cout<<"#-------------------------------------------------------------#"<<endl;
      cout<<"#                                                             #"<<endl;
      cout<<"# 1.  Mencetak Deret Kuadrat dari Bilangan Ganjil Kelipatan 3 #"<<endl;
      cout<<"#                                                             #"<<endl;
      cout<<"# 2.  Mencetak Hasil Penjumlahan dari Deret Tersebut          #"<<endl;
      cout<<"#                                                             #"<<endl;
      cout<<"###############################################################";
      cout<<endl<<endl<<endl<<"Masukkan Pilihan anda : ";
      cin>>pil;
      switch (pil)
      {
           case 1 :
                  do
                     {
                      clrscr();
                             cout<<" INPUTKAN BATAS AWAL  = "; cin>>x;
                           cout<<" INPUTKAN BATAS AKHIR = "; cin>>y;
                         if (x>=y)
                         {
                             cout<<endl<<endl<<" !!!!!! BATAS AWAL HARUS LEBIH KECIL DARI BATAS AKHIR !!!!!!";
                            getch();
                         }
                      }
                         while (x>=y);
                  cout<<endl<<endl<<" DERET NILAI KUADRAT DARI BILANGAN GANJIL KELIPATAN 3 :"<<endl;
                         for (i=x; i<=y; i++)
                        if ((i%2 != 0) && (i%3 == 0))
                        {
                           kuadrat=i*i;
                     jum=jum+kuadrat;
                          cout<<" "<<kuadrat<<"  ";
                     }
                  break;
         case 2 :
                     clrscr();
                       if (jum==0)
                         cout<<"Ops......Anda harus pilih menu 1 dulu !!!! ";
                     else
                      cout<<"HASIL PENJUMLAHAN DERET : "<<jum;
                    break;
         default :
                     clrscr();
                      cout<<"MAAF...PILIHAN ANDA SALAH !!!!";
                  break;
      }
      cout<<endl<<endl<<endl<<" MENGULANG Tekan Y, KELUAR Tekan T = ";
      cin>>lagi;
   }
}

0 komentar:

Posting Komentar

Powered By Blogger
Diberdayakan oleh Blogger.

Entri Populer

PENGUNJUNG

Buku Tamu

About Me

Foto Saya
Ijal Ferdi
there is no something special about me,,, but this blog is so special for me......
View my complete profile

Total Tayangan Halaman

Followers