You are here:

C/question on program

Advertisement


Question
QUESTION: how to print this following format:
1
01
101
0101
10101
010101
....

ANSWER: hi Saritha

You can refer to this website for many such programs its my personal website at http://www.scodz.com

void main()
{
int i, j, n = 6, c = 0;
 for(i=0;i<n;i++)
 {
   for(j=0;j<=i;j++)
   {
      printf("%d",((++c)%2));
   }
 printf("\n");
 }
}

regards
Joydeep Bhattacharya
http://www.scodz.com



---------- FOLLOW-UP ----------

QUESTION: Thank you very much for your reply.But i am not getting the exact format what i have mentioned.every line should end with '1'.

Answer
Hi Saritha

Simply change the start point
void main()
{
int i, j, n = 6, c = 1;
for(i=0;i<n;i++)
{
  for(j=0;j<=i;j++)
  {
     printf("%d",((++c)%2));
  }
printf("\n");
}
}

Check this out and lemme know its ok or not.

regards
Joydeep Bhattacharya
http://www.scodz.com

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Joydeep Bhattacharya

Expertise

Ability to solve C and Data Structure problems and puzzles with simple and easy to understand logic.

Experience

C, C++, Java, Data Structure, PHP, Web Designing

Organizations
http://www.scodz.com Designation: webmaster

Publications
http://www.scodz.com

Education/Credentials
Master of Computer Applications

Past/Present Clients
http://analysingc.50webs.com http://www.funforu.com

©2012 About.com, a part of The New York Times Company. All rights reserved.