Jumat, 01 April 2016

tugas pertemuan 5
dev c++ 5.2

#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
int a,b;
cout<<"masukan nilai a: ";
cin>>a;
cout<<"masukkan nilai b: ";
cin>>b;
if (a>b)
cout<<"nilai angka a lebih besar";
else if(a=b)
cout<<"nilai a dan b sama besar";
else
cout<<"nilai angka b lebih besar";
return 0;
}
 flowchat 5.2


dev c++ 5.3

#include <iostream>
#include <math.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
float pangkat(int x,int y)
{ return(exp(y*log(x)));
}
int main(int argc, char** argv) {
float hasil;
int a,b;
cout<<"=====menghitung hasil perpangkatan======\n"<<endl;
cout<<"tulis sebuah bilangan: ";cin>>a;
cout<<"mau dipangkat berapa: ";cin>>b;
hasil=pangkat(a,b);
cout<<a<<" pangkat "<<b<<" = "<<hasil;
return 0;
}

flowchat 5.3




dev c++ 5.4

#include <iostream>
#include <math.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int kali(int m, int n)
{int i,hasil=0;
for(i=0;i<=abs(n);i++)
hasil+=m;
if(n<0)return(-hasil);else return(hasil);
}
int main(int argc, char** argv) {
int a,b,i;
cout<<"masukkan nilai a: ";cin>>a;
cout<<"masukkan nilai b: ";cin>>b;
cout<<"nilai"<<a<<"x"<<b<<"="<<kali(a,b);
return 0;
}

flowchat 5.4




dev c++ 5.5

#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
void factorial (int n, int x, int hasil){
if(x>n)
{
cout<<"Factorial  "<<n<<"  adalah  "<<hasil<<endl; }
else
{
hasil=hasil*x;
x=x+1;
factorial(n,x,hasil);
}
}

int main(int argc, char** argv) {
int hasil;
int n;
int x;
cout<<"Masukkan nilai factorial : ";
cin>>n;
x=1;
hasil=1;
factorial(n,x,hasil);
return 0;
}

flowchat 5.5




dev c++ 5.6

#include <iostream>
#include <string>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
void fibonacci(int n, int f1, int f2, int x){
int f3;
if(x>(n-2))
{
}
else
{
f3=f1+f2;
cout<<f3<<", ";
f1=f2;
f2=f3;
x=x+1;
fibonacci(n,f1,f2,x);
}
}
int main(int argc, char** argv) {
int f1;
int n;
int f2;
int x;
cout<<"Masukkan suku ke-n : ";
cin>>n;
cout<<"fibonacci suku ke-"<<n<<endl;
x=1;
f1=0;
f2=1;
cout<<f1<<", "<<f2<<", ";
fibonacci(n,f1,f2,x);
return 0;
}

flowchat 5.6




dev c++ 5.8

#include <iostream>
#include <string>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
void ptx(int m, int n, int r){

r=m%n;
if(r==0)
{
}
else
{
cout<<r<<endl;
m=n;
n=r;
ptx(m,n,r);
}
}
int main(int argc, char** argv) {
int m,n,r;
cout<<"Masukkan bilangan pertama : ";
cin>>m;
cout<<"Masukkan bilangan kedua : ";
cin>>n;
cout<<"Nilai m : "<<m<<endl;
cout<<"Nilai n : "<<n<<endl;
r=1;
ptx(m,n,r);
return 0;
}

flowchat 5.8




Tidak ada komentar:

Posting Komentar