Kamis, 12 April 2012

print the number is divisible by 5 and 7 between 1 to 100 are then converted into a recursive iterative

#include <iostream>
#include <string>

using namespace std;

class Bagi{
      friend istream& operator>>(istream&, Bagi &);
      friend ostream& operator<<(ostream&, Bagi&);
      public:
       Bagi();
       void proses();
       int bagi(int a);
       private:
       int a;
       };

Bagi::Bagi(){
cout<<"Menampilkan bilangan yang habis dibagi 5 dan 7 antara 1 sampai 100"<<endl;
             }

void Bagi::proses(){//iteratif
a =1;
while (!(a>100)){
if (a % 5==0 && a % 7==0){
cout << a << endl;
}else{}
a =a+1;
}
}
int Bagi::bagi (int a){//rekursif
if (a>100){
}else
{
if (a % 5==0 && a % 7==0)
{
cout << a << endl;      }
else
{}bagi(a+1);
}}

int main(){

    Bagi X;
    X.proses();
    X.bagi(1);

system("pause");
return 0;
}

 gambar flowchartnya:
iteratif
rekursif

Tidak ada komentar:

Posting Komentar