Member Avatar for alan91

How to write a program using nested for loop to display the following output:

0
* *
0 1 2
* * * *
0 1 2 3 4
* * * *
* * *
* *
*

Recommended Answers

All 12 Replies

We will not do your homework for you. Have you tried? What code do you have so far? Do you have a specific problem? You have to show some efforts before we can help.

this is the part of programe where the * are printed and u have to reverses it as per ur choice

for(i=0;i<4;i++)
{
    for(j=0;j<4-i-1;j++)
    {
    printf("* ")
   }
   printf("\n")
 }

Here's the pseudocode:

SIZE<-10
subalg prints(){
    for (i<-0, i<SIZE/2) do
        for (j<-0, j<=i) do
            if i%2=0 then
                print j
            else
                print '*'
            end_if
        end_for
        print new line
    end_for
    for (i<-SIZE/2-1, downto 0) do
        for (j<-0, j<=i) do
            print '*'
        end_for
        print new line
    end_for
end_subalg
Member Avatar for alan91

this is what i have, but understand anything

#include <iostream>

using namespace std;

int main()
{  

for(int a = 0; a <= 4; a++)
{
 for(int b = 0; b <= a; b++)
 { 
 if(a % 2 == 0)
 {
 cout << b << " ";
 }
  else

  cout << "* "; 
  }
    cout << endl;

}

for(int c = 0; c <= 4; c++)
{
   for(int d = 4; d > c; d--)
    { 
      cout <<"* ";
    } 
      cout << endl;    
    } 

   system("pause");
   return(0);  
}
>
> for(int a = 0; a <= 4; a++)
> {
>  for(int b = 0; b <= a; b++)
>  { 
>  if(a % 2 == 0)
>  {
>  cout << b << " ";
>  }
>   else
>   cout << "* "; 
>   }
>     cout << endl;
> }
>

This is the upper part of the requirement. Here you'll print asterix if the row is odd, or you'll print all the numbers which are smaller than the current number of the row, if the row is even.
In the lower part of the requirement you'll just print out the asterixes, in reverse order.

how i can make game in C++

include <iostream>

using namespace std;
int main()

for(int a = 0; a <= 4; a++)

#include <iostream>
using namespace std;
int main()
{  
for(int a = 0; a <= 4; a++)
{
 for(int b = 0; b <= a; b++)
 { 
 if(a % 2 == 0)
 {
 cout << b << " ";
 }
  else
  cout << "* "; 
  }
    cout << endl;
}
}
for(i=0;i<4;i++)
{
    for(j=0;j<4-i-1;j++)
    {
    printf("* ")
   }
   printf("\n")
 }
> for(int a = 0; a <= 4; a++)
> {
>  for(int b = 0; b <= a; b++)
>  { 
>  if(a % 2 == 0)
>  {
>  cout << b << " ";
>  }
>   else
>   cout << "* "; 
>   }
>     cout << endl;
> }
>

The dead post - !
... It - it lives again! What have you done??!

That which was dead should have stayed dead! The grave will not be lightly robbed her rightful prize.

You fools! You've doomed us all!

Oops, didn't see the flagrant silly repeats by umer 4!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.