You are on page 1of 8

*1618003*

*000005*
Eka Puji Lestari
1.
While :
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch,
system("pause") or input loop */
int main(int argc, char** argv)
{
int X = 5;
while (X>=1)
{
int Y = 1 ;
while (Y<=X)
{
cout<<Y<<'\t';
Y++;
}
cout<<'\n';
X--;
}
return 0;
}

While do :
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch,
system("pause") or input loop */
int main(int argc, char** argv)
{
int X = 5;
do
{
int Y = 1 ;
do
{
cout<<Y<<'\t';
Y++;
}
while (Y<=X);
cout<<'\n';
X--;
}
while(X>=1);
return 0;
}

2.
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch,
system("pause") or input loop */
int main(int argc, char** argv)
{
int X = 1;
while (X<=5)
{
int Y = 1 ;
while (Y<=X)
{
cout<<X<<'\t';
Y++;
}
cout<<'\n';
X=X+2;
}
return 0;
}

While do :
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch,
system("pause") or input loop */
int main(int argc, char** argv)
{
int X = 1;
do
{
int Y = 1 ;
do
{
cout<<X<<'\t';
Y++;
}
while(Y<=X);
cout<<'\n';
X=X+2;
}
while(X<=5);
return 0;
}

You might also like