Thread: C Assignment help

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    15

    C Assignment help

    The output must be

    1
    01
    101
    0101
    10101

    If someone could point me in the right direction...
    I tried this but the result goes wrong at the third line and fourth line

    Code:
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    	int i,j,num=1,ctr=1;
       clrscr();
       for(i=1;i<=5;i++)
       {
          for(j=1;j<=i;j++)
          {
          	if(ctr%2!=0)
             {
             printf("1");
             }
             else
             {
             printf("0");
             }
          ctr++;
          }
          printf("\n");
       }
       getch();
    }

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    1. main should be
    int main(void) - read FAQ

    2. you should work on your indentation (Alt+F8 in VS)

    3. note that if you look at the digit that is in the place (i,j) you could see that when i+j is even you need to print "1" and "0" for odd sum
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    15
    Quote Originally Posted by vart View Post
    1. main should be
    int main(void) - read FAQ

    2. you should work on your indentation (Alt+F8 in VS)

    3. note that if you look at the digit that is in the place (i,j) you could see that when i+j is even you need to print "1" and "0" for odd sum

    I was working in Borland C++
    They have no indentation.
    Was tooo lazy to make everything indented.


    Anyways thanks,

    Man I cannot imagine that I did not see the obvious LOL

    Thanks a million
    Last edited by aditya_t90; 03-28-2009 at 02:44 AM.

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by aditya_t90 View Post
    I was working in Borland C++
    They have no indentation.
    Have you enabled autoindent mode?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Registered User
    Join Date
    Mar 2009
    Posts
    15
    Yes, but it still does not indent

  6. #6
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Just download Visual C++ 2008 express. It's free, and it's the best.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu
    By Krush in forum C Programming
    Replies: 17
    Last Post: 09-01-2009, 02:34 AM
  2. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 06:22 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Help with a pretty big C++ assignment
    By wakestudent988 in forum C++ Programming
    Replies: 1
    Last Post: 10-30-2006, 09:46 PM
  5. Replies: 1
    Last Post: 10-27-2006, 01:21 PM