pikniklagi

Wednesday, October 10, 2012

Buatlah Program Seperti Petunjuk


 1. Program Menghitung 10 Deret Bilangan Genap dengan Hasilnya:
     2+4+6+8+10+12+14+16+18+20=110
    
    Program list:
    #include<iostream.h>
    #include<conio.h>
     main()
    {
    cout<<"program untuk menghitung 10 deret bilangan genap "<<endl;
    int a=2,b=20,n;
    for(a=a;a<=b;a+=2)
    {
    cout<<a;
    if(a<b)
    {
    cout<<" + ";
    }
    }
    cout<<" = ";
   n=b/2;
   n=n*(n+1);
   cout<<n;
 getch();
   }
2. Progaram Menghitung 10 Deret Bilangan Ganjil dengan hasil:
    1+3+5+7+9+11+13+15+17+19=100

    Program List:
    #include<iostream.h>
    #include<conio.h>
    main()
   {
   cout<<"program untuk menghitung 10 deret bilangan ganjil"<<endl;
   int a=1,b=19,n;
   for(a=a;a<=b;a+=2)
   {
   cout<<a;
   if(a<b)
   {
   cout<<" + ";
   }
   }
   cout<<" = ";
   n=(b+1)/2;
   n=n*n;
   cout<<n;
  getch ();
   }
3. Program Menghitung Penjumlahan Deret Bilangan Genap Bentuk Segitiga dengan hasil:
    2 = 2
    2 + 4 = 6
    2 + 4 + 6 = 12
    2 + 4 + 6 + 8 = 20
    2 + 4 + 6 + 8 + 10 = 30

  Program List:
  #include<iostream.h>
  #include <stdio.h>
  #include <conio.h>
  main()
  {
  int A,i,j,jum;
cout<<"Input  :";cin>>A;
  for (i=2;i<=A;i+=2)
  {
  jum=0;
  for (j=2;j<=i;j+=2)
  {
  if (j != 2)
cout<<"+";
cout<<j;
  jum +=j;
  }
cout<<"="<<jum<<endl;
  }
cout<<endl;
  getch();
}       
  
4. Program Menghitung Perkalian deret Bilangan Ganjil membentuk segitiga siku dengan hasilnya:
   1 = 1
   1 * 3 = 3
   1 * 3 * 5 = 15
   1 * 3 * 5 * 7 = 105
   1 * 3 * 5 * 7 * 9 = 945
   
   Program List:
   #include <cstdlib>
   #include <iostream>
   #include <iomanip>
   using namespace std;
   int main(int argc, char *argv[])
   {
    int n=11;
    int baris=n/2;
    int hasil;
    int total=0;
    int k;
    for (int i=1;i<=baris;i++)
   {
        hasil=1;k=1;
        for(int j=1;j<=i;j++)
   {
        hasil=hasil*k;
        cout<<k;
        if (j==i)
        cout<<"  ";
    else
        cout<<" * ";
        k=k+2;      
    }
       cout<<setiosflags(ios::right)<<setw(10)<<" = "<<hasil<<endl;
       total=total+hasil;
    }
       cout<<setiosflags(ios::right)<<setw(10)<<" total = "<<total<<endl;
       cout<<endl;
       system("PAUSE");
       return EXIT_SUCCESS;
    }

5. Program Menghitung perkalian deret Bilangan Genap bentuk segitiga terbalik dengan hasilnya:
    10 + 8 + 6 + 4 + 2 = 30
    10 + 8 + 6 + 4 = 28
    10 + 8 + 6 = 24
    10 + 8 = 18
    10 = 10
    ---------- +
    110

    Program List:
    #include <stdio.h>
    int main(int argc, const char *argv[]) {
    int i, j;
    for(i=0;i<5;puts(""),++i) {
    int n=0;
    for(j=5;j>i;n+=2*(j--)) {
    if(j>i+1) {
    printf("%d*",2*j);
    }
    else {
    printf("%d ",2*j);
    }
    } printf("=%d",n);
    } return(0);
    }



4 comments:

Kost-Pontianak

Terima Kost Khusus perorangan Idr 500rb/bln.  Tidak menerima pasangan/ berkeluarga.   Jalan Parit H. Husin 1, Gang. Keluarga no. 7/...