Friday, 25 May 2012

Fibonacci series and arithmetic program

#include <cstdlib>
#include <iostream>

using namespace std;
class madis{
public:
void pilih();
void arit();
void vibo();

private:
int q[100];
};

void madis::pilih(){
int n;
cout<<"\n1. Aritmatik !?\n2. Vibonacci !?\n";
cout<<"\n\npilihan anda : ";
cin>>n;
if(n==1)arit();
if(n==2)vibo();
else cout<<"\n\n***selesai***\n\n";
}

void madis::arit() {
//system("cls");
int n,s,a,jml=0;
cout<<"\nMasukkan nilai awal :";cin>>s;
cout<<"masukkan beda :";cin>>a;
cout<<"masukkan batas (berapa kali diulang):";cin>>n;
cout<<"\nMaka didapat deret aritmatik\n=>";

for (int i=0;i<n;i++){
q[i]=s+i*a;
cout<<q[i]<<" ";
jml=jml+q[i];
}
cout<<"\nJumlah dari deret adalah "<<jml;
cout<<"\n\n";pilih();
}
void madis :: vibo(){
// system ("cls");
int i,a,s,d=0,n;
cout<<"\nMasukan nilai awal :";cin>>a;
cout<<"masukan batas nilai :";cin>>n;
s=a;
i=a;
cout<<"\nMaka akan didapat deretan :\n"<<i<<" ";
for (int i=0;i<n-1;i++){
q[i]=s+a;
s=a;
a=q[i];
cout<<q[i]<<" ";
d=d+q[i];
}
cout<<"\nJumlah dari deret adalah "<<d+i;
cout<<"\n\n"; pilih();
}
int main()
{
madis z;
z.pilih();

system("PAUSE");
return 0;
}

0 comments:

Post a Comment

.

.

.

.
Design by BlogSpotDesign | Ngetik Dot Com