C programming: Print this pattern 1 01 101 ...

the scientist

the scientist

@the-scientist-Q75U0E Oct 27, 2024
plz help urgently to print patern
1
01
101
0101
by using for loops in C .... .......................

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Kaustubh Katdare

    Kaustubh Katdare

    @thebigk Jan 10, 2013

    Umm, did you attempt the problem on your own? How about sharing what you've tried so far so that CEans here can help you correct it?
  • Jeffrey Arulraj

    Jeffrey Arulraj

    @jeffrey-xA7lUP Jan 14, 2013

    Here is a logic in even digits of control variable print 0 and in odd value of control variable print 1

    PS: Initialise control variable to 0
  • rahul69

    rahul69

    @rahul69-97fAOs Jan 14, 2013

    Here is another logic: keep concatenating a string with '0' and '1' alternatively and keep on printing the reverse of string 😎 .
    PS: Initialize string to '1'.
  • Nikhil Lokhande

    Nikhil Lokhande

    @nikhil-lokhande-EXmWKM Jan 14, 2013

    Try this one

    for(i=0;i<n;i++)
    for(j=0;j<=i;j++)
    if(((i-j)%2)==0)
    a[j]=1;
    else
    a[j]=0;
  • Anoop Kumar

    Anoop Kumar

    @anoop-kumar-GDGRCn Jan 14, 2013

    here is Algo

    Outer_loop (int i=1; i<NUMBER_OF_LINES ; i++)
    Inner_loop (j=i; j>0 ; j--)
    print (j%2);
    end Inner_loop
    print (New_line);
    end Outer_loop;

  • rahul69

    rahul69

    @rahul69-97fAOs Jan 14, 2013

    ianoop
    here is Algo

    Outer_loop (int i=1; i<NUMBER_OF_LINES ; i++)
    Inner_loop (j=i; j>0 ; j--)
    print (j%2);
    end Inner_loop
    print (New_line);
    end Outer_loop;

    Nice logic ! but I think it should be i< = NUMBER_OF_LINES instead of i<NUMBER_OF_LINES
  • Anoop Kumar

    Anoop Kumar

    @anoop-kumar-GDGRCn Jan 14, 2013

    rahul69
    Nice logic ! but I think it should be i< = NUMBER_OF_LINES instead of i<NUMBER_OF_LINES
    Yes.👍