Minggu, 03 April 2011

PERSONAL TASK

This time I will be posting a program that prints the number is divisible by 3 and 5 between 1 to 100.

This program
#include <cstdlib>
#include <iostream>

using namespace std;

class angka{                                                            //the name of class

public:

int cara();                                                            //declared the data type and public name

private:

int hasil;                                                            //declared data type in private

};

int angka::cara(){                                           //data type of class::contructor

hasil=0;                                                           //for additional is zero

for(int i=1;i<100;i++){                                   //the loop

if(i%3==0 && i%5==0) {                              //If statement for the option

cout<<i<<endl;

hasil+=1;                                                      //write the formula

}

}

cout<<”Semua angkanya adalah: “<<hasil<<”buah”<<endl;
return hasil;                                                    //return to hasil function
}


int main(int argc, char *argv[])
{

cout<<”Bilangan antara 1-100 yang habis dibagi 3 dan 5 adalah:”<<endl;

angka agk;                                                                       //class name and objek
agk.cara();                                                                      //objek.cara

system(“PAUSE”);
return EXIT_SUCCESS;
}


Tidak ada komentar:

Posting Komentar