Question:

How to print in c language?

by Guest33313  |  earlier

0 LIKES UnLike

following pattern

1

01

101

0101

10101

010101

Thanks in advance

 Tags:

   Report

2 ANSWERS


  1. The fun part of this problem is not just getting something to work, but figuring out a clever way to do it. I'm sure there are several solutions, here's mine:

    #include <stdio.h>

    #include <math.h>

    int main(int argc, char *argv[]) {

      int n,i,j;

      char x;

      if ((argc < 2) || (sscanf(argv[1],"%d",&n) != 1)) {

        printf("\nusage: %s <n>\n",argv[0]);

        return -1;

      }

      n = fabs(n);

      for (i = 1; i <= n; i++) {

        for (j = 0, x = i&1; j < i; j++, x ^= 1) {

          printf("%d",x);

        }

        puts("");

      }

      return 0;

    }


  2. Try FunctionX.com

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.