#include <conio.h>
#include <stdio.h>
#include <iostream.h>
void main() {
clrscr;
satu: //variabel perulangan
int i,i1,suku,suku1,baris,barisa,deret,deret1,tot; //variabel
char lagi;
i=1; //variabe i menyesuaikan ganjil
baris=0; //variabel baris menyesuaikan ganjil
deret=0; // variabel deret menyesuaikan ganjil
i1=1; //variabel menyesuaikan agar hasil genap
barisa=-1; //variabel menyesuaikan agar hasil genap
deret1=0; //variabel menyesuaikan agar hasil genap
cout<<"--------DERET GENAP--------"<<endl; //judul
cout<<"==========================="<<endl;
cout<<" Ketik jumlah suk bilangan : "; cin>>suku; //input
while (i<= suku){ //variabel 'i' kurang dari suku input
baris+=2; //baris=baris+2
deret+=baris; //deret=deret+baris
printf("%d + ", baris); //output baris
i++;
}
cout<<"\b\b= "<<deret; cout<<endl; //output total baris anga genap
cout<<endl;
cout<<"-------DERET GANJIL---------"; cout<<endl;
cout<<"============================"<<endl;
cout<<" Ketik jumlah suku bilangan : "; cin>>suku1;
while (i1<= suku1){
barisa+=2; //barisa=barisa+2
deret1+=barisa; //deret1=deret1+barisa
printf("%d + ", barisa);
i1++;
}
cout<<"\b\b= "<<deret1; cout<<endl;
cout<<endl;
tot=deret+deret1;
cout<<"Jumlah total : "<<tot; cout<<endl;
cout<<endl;
cout<<"Apakah anda ingin keluar [Y/n]:"; cin>>lagi; //perulangan goto
if(lagi=='Y'||lagi=='y')
goto dua; //kembali ke variabel dua
else //else
goto satu; //kembali ke variabel satu
dua: //variabel perulangan
cout<<"Terimakasih"; //output
getch();
}
2.Hasilnya
`
0 komentar:
Posting Komentar