DATE:29-12-2017

Q)Pattern 4 (Id-3460)

Given the value of ‘n’, develop an algorithm and write a C program to print the following pattern. When the value of ‘n’ is 5, the pattern will look as follows:

0 1 0 1 0 1

 0 1 0 1 0

  0 1 0 1

   0 1 0

    0 1

     0

Input Format

First line contains the value of ‘n’

Output Format
Print the pattern given in the question

sol:-
C-CODE:  

#include<stdio.h>
void main(){
    int n,i,j,k;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        for(j=0;j<i;j++){printf(" ");}
            for(k=n;k>i;k--){
                if((n-k+1)%2==0){
                    printf("1");}
                else{printf("0");}
            printf(" ");}
        printf("\n");}}