Write a program to get the following output ..n should be entered by user...like when n=5 the output should be110101101010101

Showing Answers 1 - 14 of 14 Answers

Preetham

  • Oct 4th, 2006
 

#include<stdio.h>

#include<conio.h>

void main()

{

int i,j,n;

clrscr();

printf("Enter the value of nn");

scanf("%d",&n);

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

{

for(j=1;j<=i;j++)

{

if(j%2!=0)

printf("1");

else

printf("0");

}

printf("n");

}

getch();

}

  Was this answer useful?  Yes

Bhavana

  • Oct 4th, 2006
 

Hi preetham,Thank you very much .... thanks a lottttttttttttttt

  Was this answer useful?  Yes

Sam

  • Oct 11th, 2006
 

int main() { char n_str[8] = {''}; int n, i, j; printf("Enter a value for n: "); scanf("%s", n_str); n = atoi(n_str); for (i = 1; i <= n; ++i) { for (j = 1; j <= i; ++j) { printf("%i", (j%2)); } printf("n"); } return 0;}

  Was this answer useful?  Yes

ABHAY

  • Oct 11th, 2006
 

#include <stdio.h>
#include <iostream.h>
int main()
{
 int i;
 int n;
 int a = 1;
 int b = 0;
 int flag;
 printf("Enter number( < 10):   n");
 scanf("%d",&n);
 for(int j =1;j<=n;j++)
 {
  i = j;
  flag = 1;
  while(i > 0)
  {
   if(flag == 1)
   {
    printf("%3d",a);
    flag = 0;
   }
   else
   {
    printf("%3d",b);
    flag = 1;
   }
   i--;
  }
  printf("n");
 }
 return 0;
}

  Was this answer useful?  Yes

NHKR

  • Oct 30th, 2006
 

void printdigits(){ int n=5; int i=0; int j=0; j=0; for(i=0;i

  Was this answer useful?  Yes

R.S.Jayasathyanarayanan

  • Dec 16th, 2006
 

#includevoid main(){int i,j,n;clrscr();printf("Enter the value of nn");scanf("%d",&n);for(i=1;i<=n;i++){ for(j=1;j<=i;j++) { if(j%2!=0) printf("1"); else printf("0"); }printf("n");}getch();}1 10101101010101

  Was this answer useful?  Yes

R.S.Jayasathyanarayanan

  • Dec 17th, 2006
 

void main()

{

                   int i,n;
                   char a[100];

                   clrscr();

                   printf("Enter the value of nn");

                   scanf("%d",&n);

                   for(i=0,j=0;i<n;i++)

                  {
                                  if(i%2!=0)
                                         a[j]="1";
                                  else
                                         a[j]="0";
                                   a[++j]='';
                                  printf("%sn",a);

                   }
                   getch();
}
}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions