Posted by: nR on: December 10, 2008
Contoh penggunaan do . . . while
1.
#include
using namespace std;
void main()
{
int a, b;
a = 1;
cout<>b;
do
{
// if (a % 2 ==0) //kelipatan 2
if ((a % 2 ==0) && (a % 3 == 0)) //kelipatan 3 genap
cout<<a<<” “;
a++;
}
while(a <= b);
system(“pause”);
}
2.
#include
#include
using namespace std;
void main()
{
int x,y,z;
cout<<”————\n”;
cout<<setw(4)<<”x”<<setw(4)<<”y”<<setw(4)<<”z”<<endl;
cout<<”————\n”;
x = 0;
y = 0;
do
{
z = 20 – x – y;
cout<<setw(4)<<x<<setw(4)<<y<<setw(4)<<z<<endl;
y++;
}
while(y<=20);
system(“pause”);
x = 1;
z = 0;
do
{
y = [...]
Recent Comments