Thread: Nested Loop

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    74
    Rep Power
    2

    Nested Loop


    Hello everyone! its me again

    my target screen output is supposedly this:

    [IMG][/IMG]

    but my actual screen output is this:(the code for space for the body is not working)



    so here is my code:

    Code:
    #include <stdio.h> 
    #include <conio.h>  
    
    int main() 
    {
     	int outer,inner,space;
    
     	 for(outer=1;outer<=9;outer+=2) 	
             {
     		for(space=7;space>=outer;space-=2);
                    {
                         printf(" ");
     		}
     		for(inner=1;inner<=outer;inner++)
     	        {
                         printf("*");
     		}
     		printf("\n");
     	}
     	for(outer=1;outer<=3;outer++)
     	{
     		for(space=2;space>=3;space++)
     	        {
     			printf(" ");
     		}
     		for(inner=1;inner<=5;inner++)
     	        {
     			printf("*");
     		}
     		printf("\n");
     	}
     	getch();
     	return 0;
     }
    PLEASE HELP! thank you
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,376
    Rep Power
    1871
    > for(space=7;space>=outer;space-=2);
    Watch the ; at the end.
    This loop does nothing.

    > for(space=2;space>=3;space++)
    The condition is immediately false, so this loop does nothing either.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    74
    Rep Power
    2
    Originally Posted by salem
    > for(space=7;space>=outer;space-=2);
    Watch the ; at the end.
    This loop does nothing.

    > for(space=2;space>=3;space++)
    The condition is immediately false, so this loop does nothing either.

    Thank You

IMN logo majestic logo threadwatch logo seochat tools logo