# Given an int variable n that has already been declared and initialized to a positive value, and another int variable j that has already been declared, use a do…while loop to print a single line consisting of n asterisks. Thus if n contains 5, five asterisks will be printed. Use no variables other than n and j.

5

### CHALLENGE:

Given an int variable n that has already been declared and initialized to a positive value, and another int variable j that has already been declared, use a do…while loop to print a single line consisting of n asterisks. Thus if n contains 5, five asterisks will be printed. Use no variables other than n and j.

### SOLUTION:

```
j=1;
do{
cout << "*";
j++;
}
while (j<=n);

```

• Alfredo says:

j = 1;

while (j<=n)
{
cout << "*";

j++;
}

• Alexa says:

for (j = 0; j < n; j++)

{

System.out.print("*");

}

• kenny john says:

j=0; // it is not j=1; it is j=0;
do
{
cout << "*";
j++;
}
while (j<n );

• Malcolm A. Morgan says:

HERE IS THE CODE FOR C:

for (j = 0; j < n; ++j){
printf("*");}

• Malcolm A. Morgan says:

j=1;
do{
printf(“*”);
j++;
}
while (j<=n);