#include <cstdlib>
#include <iostream>
using namespace std;
class perulangan{
public:
perulangan(){n=4;}
void ulang_for(int);
void ulang_while(int);
private:
int n;
};
int main(int argc, char *argv[]){
int x;
cout<<"=================================="<<endl;
cout<<" PROGRAM PERULANGAN "<<endl;
cout<<"=================================="<<endl<<endl;
cout << "Masukkan batasan : "; cin >> x;
cout << endl;
perulangan X;
cout << "Menggunakan cara iteratif" << endl;
X.ulang_for(x);
cout << "Menggunakan cara while" << endl;
X.ulang_while(x);
cout << endl;
system("pause");
return 0;
}
void perulangan::ulang_for(int n){
for (int i=1; i<=n; i++){
cout << i << " ";
}
cout << endl;
}
void perulangan::ulang_while(int n){
int i=1;
while (n>=i) {
cout << n << " ";
n--;
}
cout << endl;
}
Hasil Compilenya
Tidak ada komentar:
Posting Komentar