Program Menghitung Deret pada C++
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void main()
{ int a, n, jwb, b, c, d, bil;
char mad;
do
{ system("cls");
cout<<"PROGRAM MENGHITUNG (n) DERET\n";
cout<<"********************************\n";
cout<<" PILIH KRITERIA DERET(1/2/3/4/5 : \n";
cout<<"1. 1,2,5,10,17,26,................\n";
cout<<"2. 3,6,12,24,48,................\n";
cout<<"3. 2,6,12,24,48,...\n";
cout<<"4. 1,4,7,10,13,16,............\n";
cout<<"5. 9,16,25,36,49,64,............\n";
cout<<"********************************\n";
masuk:
cout<<"Pilihan Anda : ";
cin>>jwb;
switch(jwb)
case 1:
{ cout<<"Masukkan n deret hitung : ";
cin>>n;
b=1; c=1; d=2; a=1;
while ( b<=n)
{
cout << " "<<a ;
a=a+c;
c=c+d;
b++;
}
cout<<endl;
}break;
case 2:
{ cout<<"Masukkan n deret hitung : ";
cin>>n;
cout<<endl;
bil=3;
while (bil<=n)
{
cout << " "<<bil ;
bil*=2;
}
cout<<endl;
}break;
case 3:
{ cout<< "masukkan jumlah baris = ";
cin >> n;
cout<<endl;
b=4; c=4; d=2; a=2;
while (b<=n)
{
cout << " "<<a ;
a=a+c;
c=c+d;
b++;
}
cout<<endl;
}break;
case 4:
{ cout<< "masukkan jumlah baris = ";
cin >> n;
cout<<endl;
while (bil=1; bil<=n; bil+=3)
{
cout << " "<<bil ;
}
cout<<endl;
}break;
case 5:
{ cout<< "masukkan jumlah baris = ";
cin >> n;
cout<<endl;
b=7; c=7; d=2;
while (a=9; b<=n; b++)
{
cout << " "<<a ;
a=a+c;
c=c+d;
}
cout<<endl;
}break;
default;
{ cout<<"Pilihan (n) deret anda tidak tersedia\n";
cout<<"Mohon di inputkan kembali pilihan anda.\n";
goto masuk;
}
cout<<"\n\n Apakah anda ingin input data lagi(Y/T)? : ";
cin>>mad;
}
while(mad=='Y'||mad=='y');
cout<<"\n **** SELAMAT ANDA BERHASIL ****\n";
}
#include<conio.h>
#include<stdlib.h>
void main()
{ int a, n, jwb, b, c, d, bil;
char mad;
do
{ system("cls");
cout<<"PROGRAM MENGHITUNG (n) DERET\n";
cout<<"********************************\n";
cout<<" PILIH KRITERIA DERET(1/2/3/4/5 : \n";
cout<<"1. 1,2,5,10,17,26,................\n";
cout<<"2. 3,6,12,24,48,................\n";
cout<<"3. 2,6,12,24,48,...\n";
cout<<"4. 1,4,7,10,13,16,............\n";
cout<<"5. 9,16,25,36,49,64,............\n";
cout<<"********************************\n";
masuk:
cout<<"Pilihan Anda : ";
cin>>jwb;
switch(jwb)
case 1:
{ cout<<"Masukkan n deret hitung : ";
cin>>n;
b=1; c=1; d=2; a=1;
while ( b<=n)
{
cout << " "<<a ;
a=a+c;
c=c+d;
b++;
}
cout<<endl;
}break;
case 2:
{ cout<<"Masukkan n deret hitung : ";
cin>>n;
cout<<endl;
bil=3;
while (bil<=n)
{
cout << " "<<bil ;
bil*=2;
}
cout<<endl;
}break;
case 3:
{ cout<< "masukkan jumlah baris = ";
cin >> n;
cout<<endl;
b=4; c=4; d=2; a=2;
while (b<=n)
{
cout << " "<<a ;
a=a+c;
c=c+d;
b++;
}
cout<<endl;
}break;
case 4:
{ cout<< "masukkan jumlah baris = ";
cin >> n;
cout<<endl;
while (bil=1; bil<=n; bil+=3)
{
cout << " "<<bil ;
}
cout<<endl;
}break;
case 5:
{ cout<< "masukkan jumlah baris = ";
cin >> n;
cout<<endl;
b=7; c=7; d=2;
while (a=9; b<=n; b++)
{
cout << " "<<a ;
a=a+c;
c=c+d;
}
cout<<endl;
}break;
default;
{ cout<<"Pilihan (n) deret anda tidak tersedia\n";
cout<<"Mohon di inputkan kembali pilihan anda.\n";
goto masuk;
}
cout<<"\n\n Apakah anda ingin input data lagi(Y/T)? : ";
cin>>mad;
}
while(mad=='Y'||mad=='y');
cout<<"\n **** SELAMAT ANDA BERHASIL ****\n";
}
Comments
Post a Comment
Terimakasih telah berkunjung dan berkomentar disini...