#include <iostream.h>
#include <conio.h>
#include <math.h>
class Deret{
public :
int DeretAritmatika(int n);
float DeretGeometri(float a,float r,int n);
private :
};
// fungsi DeretAritmatika
int Deret::DeretAritmatika(int n){
int jumlah=0;
for (int i=1;i<=n;i++){
jumlah+=i;
}
cout << " Hasil Deret Aritmatika : " <<jumlah;
return 0;
}
// fungsi DeretGeometri
float Deret::DeretGeometri(float a,float r,int n){
float jumlah=a;
for (float i=1;i<=n;i++){
jumlah+=a*(r,i);
}
cout << " Hasil Deret Geometri : " <<jumlah;
return 0;
}
void main(){
Deret X;
int pil;
ulang:
cout << " Kumpulan Hitung Deret :\n";
cout << " 1. Deret Aritmatika \n";
cout << " 2. Deret Geometri \n";
cout << " Pilihan Anda [1,2] : ";
cin >>pil;
switch(pil){
case 1:
int n;
cout << " \n Menghitung Deret Aritmatika \n";
cout << " Masukkan Bilangan Bulat(n) : ";
cin >> n;
X.DeretAritmatika(n);
break;
case 2:
int a,r;
cout << " \n Menghitung Deret Geometri\n";
cout << " Masukkan Bilangan real(a) : ";
cin >> a;
cout << " Masukkan Bilangan real(r) : ";
cin >> r;
cout << " Masukkan Bilangan Bulat(n) : ";
cin >> n;
X.DeretGeometri(a,r,n);
break;
default:
cout << " Masukkan Salah, Silahkkan ulangi lagi..? ";
getch();
clrscr();
goto ulang;
break;
}
getch();
}
0 comments:
Posting Komentar