Tugas3_kombinasi Dan Permutasi, Faktorial, Dan Fibonacci
-
Upload
habibatur-rofiah -
Category
Documents
-
view
55 -
download
3
Transcript of Tugas3_kombinasi Dan Permutasi, Faktorial, Dan Fibonacci
//TUGAS KOMBINASI DAN PERMUTASI#include"iostream"#include"conio.h"#include"stdlib.h"
using namespace std;
void menu();void ulang();void proses();void menuKom();void menuPer();void menuInput();
long int nomor1, nomor2, hit1, hit2, bil1, bil2, bil3;long int fak(long int);
void menu(){ int a; cout<<"\nPERHITUNGAN KOMBINASI DAN PERMUTASI\n1. KOMBINASI\n2.
PERMUTASI\n3. EXIT\n\nPilihan ANDA : "; cin>>a; switch(a){ case 1:menuKom(); ulang(); break; case 2:menuPer(); ulang(); break; case 3:system("exit"); break; default:menu(); break; }}
void ulang(){ int b; cout<<"\n\nULANGI PERHITUNGAN??? <Y=1 , N=0> --> "; cin>>b; switch(b){ case 0: system("exit"); break;
case 1: menu(); break; default: ulang(); break; }}
main(){ menu(); getch();}
void menuKom(){ cout<<"Program Menghitung Kombinasi <nCr> \n"; menuInput(); proses(); hit1=bil1/bil3; cout<<"\nHasil dari "<<nomor1<<" kombinasi "<<nomor2<<" adalah "<<hit1; return;}
void menuInput(){ cout<<"Masukkan Nilai n: "; cin>>nomor1; cout<<"Masukkan Nilai r: "; cin>>nomor2;}
void menuPer(){ cout<<"Program Menghitung Permutasi <nPr> \n"; menuInput(); proses(); hit2=bil1/(bil3*bil2); cout<<"\nHasil dari "<<nomor1<<" Permutasi "<<nomor2<<" adalah "<<hit2; return;}
void proses(){ bil1=fak(nomor1); bil2=fak(nomor2);
Nama : FUAD AINUN NAJIBNIM : 11650039
bil3=fak(nomor1-nomor2);}long int fak(long int n){ int f; if(n<=1){ f=1; } else { f=n*fak(n-1); } return (f);}
//TUGAS FAKTORIAL#include"iostream"#include"conio.h"
using namespace std;
long int fak(long int);
main(){ long int nomor, hasil; cout<<"MENU FAKTORIAL\nSilahkan Masukkan Nilainya : "; cin>>nomor; hasil=fak(nomor); cout<<"\nHasil FAKTORIAL dari "<<nomor<<" adalah "<<hasil; getch();}
long int fak(long int n){ int f; if(n<=1){ f=1; } else { f=n*fak(n-1); } return (f);}
Nama : FUAD AINUN NAJIBNIM : 11650039
//TUGAS FIBONACCI#include"iostream"#include"conio.h"
using namespace std;long int fibonacci[100], nomor1, nomor2; f=0, d=0, c=1;long int proses(long int, long int);
main(){ cout<<"Program BILANGAN FIBONACCI \nMasukkan Jumlah Bilangan Binonacci
(max=100) : "; cin>>nomor1; cout<<"dari Angka (Angka Awal) : "; cin>>nomor2; cout<<"\n=============================================\n"; cout<<nomor1<<" bilangan Fibonacci dari "<<nomor2<<" adalah :\n"; proses(nomor1, nomor2); getch();}
long int proses(long int a, long int b){ if(a<=1){ f=0; } else { if(c<=1){ fibonacci[f]=b; cout<<fibonacci[f]<<"\t"; c++; f++; proses(a-1, b); } else { fibonacci[f]=b; cout<<fibonacci[f]<<"\t"; d=b+fibonacci[f-1]; f++; proses(a-1, d); } }
}
Nama : FUAD AINUN NAJIBNIM : 11650039