Thread: Beginner Please help.

  1. #1
    Registered User
    Join Date
    Jan 2017
    Posts
    1

    Beginner Please help.

    I created a program for printing number from 0 to 10. The program is given below.

    Code:
    #include<Stdio.h>
    void main()
    {
        int i=0;
        for(i=0;i<=10;i++)
        {
            printf("%d",i);
            printf("\n");
            printf("\t");
        }
    }

    Im getting output :

    0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10


    But after some modification to program (placing printf("\t"); above printf("%d",i); )

    The new program
    Code:
    #include<Stdio.h>
    void main()
    {
        int i=0;
        for(i=0;i<=10;i++)
        {
            printf("\t");
            printf("%d",i);
            printf("\n");
    
        }
    }

    0
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

    Please help. why in first program 0 is not getting the vertical tab but all other numbers after 0 got vetical tab and in second program all numbers got vertical tab.
    Thank you..

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,663
    > printf("0");
    > printf("\n");
    > printf("\t");
    If you ran this code just once, why would you believe that \t would come before the 0 ?
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Question -- From Absolute Beginner's Guide to C
    By Dghelerter in forum C Programming
    Replies: 5
    Last Post: 12-26-2013, 01:30 PM
  2. Beginner Help Plz :D
    By xanimeangiex in forum C++ Programming
    Replies: 3
    Last Post: 11-13-2010, 07:43 AM
  3. Beginner: help?
    By Baltz in forum C Programming
    Replies: 4
    Last Post: 11-12-2010, 03:50 AM
  4. Need help.. beginner
    By scarlet00014 in forum C Programming
    Replies: 2
    Last Post: 09-27-2008, 04:11 AM
  5. Windows programming for beginner (Absolute beginner)
    By WDT in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2004, 11:21 AM

Tags for this Thread