Welcome to Dream.In.Code
Become a C++ Expert!

Join 150,224 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,248 people online right now. Registration is fast and FREE... Join Now!




Loop Manipulation

 
Reply to this topicStart new topic

Loop Manipulation

salman
9 Dec, 2007 - 11:40 PM
Post #1

New D.I.C Head
*

Joined: 21 Nov, 2007
Posts: 19


My Contributions
CODE

#include <stdio.h>
#include <conio.h>
void main ()
{
    int a, b; //variables
    clrscr ();

//Nested Loop below
    for (a=1; a<=5; a++)
    {
        for (b=1; b<=a; b++)
        {
            printf ("\t%d",a);
        }
        printf (" \n");
    }
    for (a=4; a>=1; a--)
    {
        for (b=1; b<=a; b++)
        {
            printf ("\t%d",a);
        }
        printf (" \n");
    }
    getch ();
}



i want to create this program. In diamond shape.

* 1 *
* 2 2 *
* 3 3 3 *
* 4 4 4 4 *
* 5 5 5 5 5 *
* 4 4 4 4 *
* 3 3 3 *
* 2 2 *
* 1 *
When i Compile my program it look like this


1
22
333
4444
55555
4444
333
22
1

I want to make this program in the center of the screen and also in diamond shape but i don't know ho to do this. I dont know where to use gotoxy stament to make the program in center.
so help me out to create center diamond Shape Counting.

This post has been edited by salman: 10 Dec, 2007 - 12:16 AM
User is offlineProfile CardPM
+Quote Post

Nayana
RE: Loop Manipulation
10 Dec, 2007 - 12:05 AM
Post #2

DIC Hawk - 나야나 नयन:
Group Icon

Joined: 14 Nov, 2007
Posts: 824



Thanked: 5 times
Dream Kudos: 175
My Contributions
Firstly, you need to code.gif

Also, the first printf command uses a non-existent variable called "B". This should be "b"

Thirdly, your code currently goes

1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

If you want
1
2 2

etc. you should print out the value of "a" in both.

To indent your lines, you can use spaces.
Count from the number a to the number 5. To do this, before printing the rest of the line.

Try to do this. If it doesn't work, post your (new) code back here
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Loop Manipulation
10 Dec, 2007 - 07:36 AM
Post #3

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,869



Thanked: 53 times
Dream Kudos: 550
My Contributions
CODE

   for (a=1; a<=5; a++)
    {
        //here is where your goto, or spacing would go to center the image
        for (b=1; b<=a; b++)
        {
            printf ("\t%d",a);
        }
        printf (" \n");
    }

User is offlineProfile CardPM
+Quote Post

salman
RE: Loop Manipulation
11 Dec, 2007 - 05:22 AM
Post #4

New D.I.C Head
*

Joined: 21 Nov, 2007
Posts: 19


My Contributions
CODE

   for (a=1; a<=5; a++)
    {
        //here is where your goto, or spacing would go to center the image
        for (b=1; b<=a; b++)
        {
            printf ("\t%d",a);
        }
        printf (" \n");
    }


But tell me what i write in goto statement???????????????

Please help me...
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/9/09 05:58AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month