Computer Science, asked by Monkiko, 1 month ago

WAP to print the following pattern

1
1 0
1 0 1
1 0 1 0
1 0 1 0 1

Answers

Answered by sandipan2224
1

Answer:

Required C++ program is given below:

#include<iostream>

using namespace std;

int main()

{

   int i,j;

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

   {

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

           cout<<(j%2)?"1 ":"0 ";

       }

       cout<<"\n";

   }

}

Explanation:

The statement inside the inner loop is basically synonymous to this-

if(j%2==1){

   cout<<"1 ";

}

else{

   cout<<"0 ";

}

Hope this helps.

Answered by goludeshamukh50
0

Ans - C program to print following pattern 1 01 101 0101

/*

Program to print following pattern-

1

01

101

0101

10101

*/

#include<stdio.h>

#include<conio.h>

void main()

{

int i,j,n;

clrscr();

printf("\n Enter the value of n:");

scanf("%d",&n);

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

{

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

{

if((i+j)%2==0)

{

printf("\t 0");

}

else

{

printf("\t 1");

}

}

printf("\n");

}

getch();

Similar questions