Wednesday, January 12, 2011

Bab Perulangan


Program Hitung 10 Deret  Bilangan Genap

/**Latihan Bab 6 no1 **/
/** Created by: Ipah Hanifah **/
      #include<stdio.h>
#include<conio.h>
#include<iostream.h>
main()
{
int a=2,b=20,n;
clrscr();
printf("PROGRAM MENGHITUNG DERET BILANGAN GENAP\n\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();
}
Output:







__________________________________________________

Program Hitung 10 Deret Bilangan Ganjil 

/**Latihan Bab6  no2**/
/** Created by: Ipah Hanifah **/
#include<conio.h>
      #include<stdio.h>
#include<conio.h>
#include<iostream.h>
main()
{
int a=1,b=19,n;
clrscr();
printf("PROGRAM MENGHITUNG DERET BILANGAN GANJIL\n\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();
}






__________________________________________________
  Program Hitung Jumlah Deret Bilangan Membentuk Segitiga
/**Latihan Bab6  no2**/
/** Created by: Ipah Hanifah **/
      #include<stdio.h>
#include<conio.h>
#include<iostream.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();
}


Output


No comments:

Post a Comment

Goresan pena Si Pengemis ilmu © 2008. Design by :vio Templates Sponsored by: gold bola