Thread: Gotoxy along with FOR Loop

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    6

    Gotoxy along with FOR Loop

    I want to know that how can I print numbers from 1 to 10 in a way mentioned below :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10




    I'm stuck on following ..
    Code:
    # include <stdio.h>
    # include <conio.h>
    
    main()
    {
    int a;
    
    clrscr();
    
    for (a=1; a<=10; a++)
    {           gotoxy(a,a);
                printf("%d",a);
                printf("\n");                      }
    
    getch();
    }

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    What do you mean 'stuck on the following'

    Form a COHERENT query, with some detail about what is going wrong in it - from your point of view.

    there is no point outputting a new line because your cursor is moved by gotoxy every iteration of the loop anyway isnt it?

    using (a,a) all that is going to happen is you are getting output at coordinates, : (1,1) , (2,2) , (3,3) , (4,4)

    what shape do you think that will output, versus what you want to achieve?

    And:

    Code:
    int main() { return 0; }
    And ditch the bloomin turbot sea.
    Last edited by rogster001; 02-07-2012 at 07:04 AM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Code:
    # include <stdio.h>
     
    int main()
    {
      int a;
     
      for ( a=1; a <= 10 ; a++ )
      {
         // find a way to print 5 spaces if a is an even number
         printf("%d\n",a);
      }
     
      getch();
    
      return 0;
    }
    Your code uses nonstandard functions. Try to stick to the standard, so it will work on any operating system and with any compiler. I removed the nonstandard parts. All you need to do is to check if the content of your "a" variable is even (i.e. 2 or 4 or 6 or 8) and print more spaces before you print the number.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  4. #4
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Closed for double posting. This is C, so I will let the C board thread survive.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Gotoxy along with FOR Loop
    By HellHands in forum C Programming
    Replies: 8
    Last Post: 02-07-2012, 11:05 AM
  2. gotoxy....help
    By Souradeep in forum C++ Programming
    Replies: 4
    Last Post: 12-20-2010, 09:11 PM
  3. how to use gotoxy()??
    By Beginnerinc in forum C Programming
    Replies: 5
    Last Post: 08-15-2010, 12:23 PM
  4. gotoxy
    By BEN10 in forum C Programming
    Replies: 4
    Last Post: 08-03-2009, 12:11 PM
  5. gotoxy()
    By Commander in forum C Programming
    Replies: 3
    Last Post: 05-28-2002, 04:33 PM