Rabu, 06 April 2016

ITERATIF DAN REKRUSIF NO 1

PROGRAM C++

INTERATIF:

#include <iostream>

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






int main(int argc, char** argv) {
int a;
int batas;
a=1;
batas=100;
while (!(a==batas)){
if(a%5==0 && a%7==0){
cout<<a<<endl;
}
else{
}
a=a+1;
}



return 0;
}


REKRUSIF:

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



class Bilangan{

private:

int x,y;

public:

Bilangan(){x=1;y=100;}

int rekursif(int x,int y);

void rekursif();

};



int Bilangan::rekursif(int x,int y){



if (x<=100){

if (x%5==0 && x%7==0){

cout<<"hasil :"<<x<<endl;

}

return rekursif(x+1,y);

}

}
int main(int argc, char** argv) {

;

{   Bilangan z;

z.rekursif(1,100);

}
return 0;
}


semoga bermanfaat ya men.

Tidak ada komentar:

Posting Komentar