PLAY WITH CODING

Home Basic Program If & Else Loops Conversion Pattern logo

Program Based on Pattern

SOURCE CODE

PROBLEM-1

* * * *
* * *
* *
*

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             printf(" ");
          for(int j=1;j<=i;j++)
      {
             printf("* ");
      }
        printf("\n");
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
      int num;
      cout<<"enter number of rows : ";
      cin>>num;
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             cout<<" ";
         for(int j=1;j<=i;j++)
      {
             cout<<"* ";
      }
        cout<<"\n";
    }
    return 0;
}


Output

Enter number of rows :- 4

* * * *
* * *
* *
*

PROBLEM-2

* * * * * * *
*       *
*  *
*

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      for(int i=num;i>=1;i--)
    {
         for(int space=num;space>i;space--)
             printf(" ");
         for(int j=1;j<2*i;j++)
      {
             if(i==num||(j==1||j==2*i-1))
             printf("*");
             else
             printf(" ");
      }
        printf("\n");
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
      int num;
      cout<<"enter number of rows : ";
      cin>>num;
      for(int i=num;i>=1;i--)
    {
         for(int space=num;space>i;space--)
             cout<<" ";
         for(int j=1;j<2*i;j++)
      {
             if(i==num ||(j==1||j==2*i-1))
             cout<<"*";
             else
             cout<<" ";
      }
        cout<<"\n";
    }
    return 0;
}


Output

Enter number of rows :- 4

* * * * * * *
*       *
*  *
*

PROBLEM-3

1 2 3 4
1 2 3
1 2
1

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             printf(" ");
         for(int j=1;j<=i;j++)
      {
             printf("%d ",j);
      }
        printf("\n");
    }
    return 0;
}


#include  <iostream>
using namespace std;
int main()
{
      int num;
      cout<<"enter number of rows : ";
      cin>>num;
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             cout<<" ";
         for(int j=1;j<=i;j++)
      {
             cout<<j<<" ";
      }
        cout<<"\n";
    }
    return 0;
}


Output

Enter number of rows :- 4

1 2 3 4
1 2 3
1 2
1

PROBLEM-4

A B C D
A B C
A B
A

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      char ch;
      for(int i=num;i>=1;i--)
    {
         ch='A';
         for(int space=1;space<=num-i;space++)
             printf(" ");
         for(int j=1;j<=i;j++)
      {
             printf("%c ",ch);
             ch++;
      }
        printf("\n");
    }
    return 0;
}


#include  <iostream>
using namespace std;
int main()
{
      int num;
      cout<<"enter number of rows : ";
      cin>>num;
      char ch;
      for(int i=num;i>=1;i--)
    {
         ch='A';
         for(int space=1;space<=num-i;space++)
             cout<<" ";
         for(int j=1;j<=i;j++)
      {
             cout<<ch<<" ";
             ch++;
      }
        cout<<"\n";
    }
    return 0;
}


Output

Enter number of rows :- 4

A B C D
A B C
A B
A

PROBLEM-5

1 1 1 1
2 2 2
3 3
4

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      int a=1;
      for(int i=1;i<=num;i++)
    {
         for(int space=1;space<=num-i;space++)
             printf(" ");
         for(int j=1;j<=i;j++)
      {
             printf("%d ",a);
      }
         a++;
        printf("\n");
    }
    return 0;
}


#include  <iostream>
using namespace std;
int main()
{
      int num,a=1;
      cout<<"enter number of rows : ";
      cin>>num;
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             cout<<" ";
         for(int j=1;j<=i;j++)
      {
             cout<<a<<" ";
      }
         a++;
        cout<<"\n";
    }
    return 0;
}


Output

Enter number of rows :- 4

1 1 1 1
2 2 2
3 3
4

PROBLEM-6

A A A A
B B B
C C
D

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      char ch='A';
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             printf(" ");
         for(int j=1;j<=i;j++)
      {
             printf("%c ",ch);
      }
         ch++;
        printf("\n");
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
      int num;
      cout<<"enter number of rows : ";
      cin>>num;
      char ch='A';
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             cout<<" ";
         for(int j=1;j<=i;j++)
      {
             cout<<ch<<" ";
      }
         ch++;
        cout<<"\n";
    }
    return 0;
}


Output

Enter number of rows :- 4

A A A A
B B B
C C
D

PROBLEM-7

1 2 3 4
5 6 7
8 9
10

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      int k=1;
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             printf(" ");
         for(int j=1;j<=i;j++)
      {
             printf("%d ",k);
             k++;
      }
        printf("\n");
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
      int num;
      cout<<"enter number of rows : ";
      cin>>num;
      int k=1;
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             cout<<" ";
         for(int j=1;j<=i;j++)
      {
             cout<<k<<" ";
             k++;
      }
        cout<<"\n";
    }
    return 0;
}


Output

Enter number of rows :- 4

1 2 3 4
5 6 7
8 9
10

PROBLEM-8

A B C D
E F G
H I
J

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      char ch='A';
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             printf(" ");
         for(int j=1;j<=i;j++)
      {
             printf("%c ",ch);
             ch++;
      }
        printf("\n");
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
      int num;
      cout<<"enter number of rows : ";
      cin>>num;
      char ch='A';
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             cout<<" ";
         for(int j=1;j<=i;j++)
      {
             cout<<ch<<" ";
             ch++;
      }
        cout<<"\n";
    }
    return 0;
}


Output

A B C D
E F G
H I
J

PROBLEM-9

0 0 0 0
1 1 1
0 0
1

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      int k=1;
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             printf(" ");
         for(int j=1;j<=i;j++)
      {
             if(i%2!=0)
             printf("0 ");
             else
             printf("1 ");
      }
        printf("\n");
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
      int num;
      cout<<"enter number of rows : ";
      cin>>num;
      int k=1;
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             cout<<" ";
         for(int j=1;j<=i;j++)
      {
             if(i%2!=0)
             cout<<"0 ";
             else
             cout<<"1 ";
      }
        cout<<"\n";
    }
    return 0;
}


Output

Enter number of rows :- 4

0 0 0 0
1 1 1
0 0
1

PROBLEM-10

1*2*3*4
1*2*3
1*2
1

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             printf(" ");
         for(int j=1;j<=i;j++)
      {
             if(j!=1)
             printf("*%d",j);
             else
             printf("%d",j);
      }
        printf("\n");
    }
    return 0;
}


#include  <iostream>
using namespace std;
int main()
{
      int num;
      cout<<"enter number of rows : ";
      cin>>num;
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             cout<<" ";
         for(int j=1;j<=i;j++)
      {
             if(j!=1)
             cout<<"*"<<j;
             else
             cout<<j;
      }
        cout<<"\n";
    }
    return 0;
}


Output

Enter number of rows :- 4

1*2*3*4
1*2*3
1*2
1

PROBLEM-11

A*B*C*D
A*B*C
A*B
A

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      char ch;
      for(int i=num;i>=1;i--)
    {
         ch='A';
         for(int space=1;space<num-i;space++)
             printf(" ");
         for(int j=1;j<=i;j++)
      {
             if(j!=1)
             printf("*%c",ch);
             else
             printf("%c",ch);
             ch++;
      }
        printf("\n");
    }
    return 0;
}


#include  <iostream>
using namespace std;
int main()
{
      int num;
      cout<<"enter number of rows : ";
      cin>>num;
      char ch;
      for(int i=num;i>=1;i--)
    {
         ch='A';
         for(int space=1;space<num-i;space++)
             cout<<" ";
         for(int j=1;j<=i;j++)
      {
             if(j!=1)
             cout<<"*"<<ch;
             else
             cout<<ch;
             ch++;
      }
        cout<<"\n";
    }
    return 0;
}


Output

Enter number of rows :- 4

A*B*C*D
A*B*C
A*B
A

PROBLEM-12

1*1*1*1
2*2*2
3*3
4

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      int a=1;
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             printf(" ");
         for(int j=1;j<=i;j++)
      {
             if(j!=1)
             printf("*%d",a);
             else
             printf("%d",a);
      }
         a++;
        printf("\n");
    }
    return 0;
}


#include  <iostream>
using namespace std;
int main()
{
      int num,a=1;
      cout<<"enter number of rows : ";
      cin>>num;
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             cout<<" ";
         for(int j=1;j<=i;j++)
      {
             if(j!=1)
             cout<<"*"<<a;
             else
             cout<<a;
      }
         a++;
        cout<<"\n";
    }
    return 0;
}


Output

Enter number of rows :- 4

1*1*1*1
2*2*2
3*3
4

PROBLEM-13

A*A*A*A
B*B*B
C*C
D

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      char ch='A';
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             printf(" ");
         for(int j=1;j<=i;j++)
      {
             if(j!=1)
             printf("*%c",ch);
             else
             printf("%c",ch);
      }
         ch++;
        printf("\n");
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
      int num;
      cout<<"enter number of rows : ";
      cin>>num;
      char ch='A';
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             cout<<" ";
         for(int j=1;j<=i;j++)
      {
             if(j!=1)
             cout<<"*"<<ch;
             else
             cout<<ch;
      }
         ch++;
        cout<<"\n";
    }
    return 0;
}


Output

Enter number of rows :- 4

A*A*A*A
B*B*B
C*C
D

PROBLEM-14

1*2*3*4
5*6*7
8*9
10

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      int k=1;
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             printf(" ");
         for(int j=1;j<=i;j++)
      {
             if(j!=1)
             printf("*%d",k);
             else
             printf("%d",k);
             k++;
      }
        printf("\n");
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
      int num;
      cout<<"enter number of rows : ";
      cin>>num;
      int k=1;
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             cout<<" ";
         for(int j=1;j<=i;j++)
      {
             if(j!=1)
             cout<<"*"<<k;
             else
             cout<<k;
             k++;
      }
        cout<<"\n";
    }
    return 0;
}


Output

Enter number of rows :- 4

1*2*3*4
5*6*7
8*9
10

PROBLEM-15

A*B*C*D
E*F*G
H*I
J

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      char ch='A';
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             printf(" ");
         for(int j=1;j<=i;j++)
      {
             if(j!=1)
             printf("*%c",ch);
             else
             printf("%c",ch);
             ch++;
      }
        printf("\n");
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
      int num;
      cout<<"enter number of rows : ";
      cin>>num;
      char ch='A';
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             cout<<" ";
         for(int j=1;j<=i;j++)
      {
             if(j!=1)
             cout<<"*"<<ch;
             else
             cout<<ch;
             ch++;
      }
        cout<<"\n";
    }
    return 0;
}


Output

Enter number of rows :- 4

A*B*C*D
E*F*G
H*I
J

PROBLEM-16

* * * * * * *
* * * * *
* * *
*

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             printf("  ");       /* double space*/
          for(int j=1;j<=2*i-1;j++)
      {
             printf("* ");
      }
        printf("\n");
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
      int num;
      cout<<"enter number of rows : ";
      cin>>num;
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             cout<<"  ";       /* double space*/
         for(int j=1;j<=2*i-1;j++)
      {
             cout<<"* ";
      }
        cout<<"\n";
    }
    return 0;
}


Output

Enter number of rows :- 4

* * * * * * *
* * * * *
* * *
*

PROBLEM-17

1 2 3 4 5 6 7
1 2 3 4 5
1 2 3
1

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             printf("  ");       /* double space*/
         for(int j=1;j<=2*i-1;j++)
      {
             printf("%d ",j);
      }
        printf("\n");
    }
    return 0;
}


#include  <iostream>
using namespace std;
int main()
{
      int num;
      cout<<"enter number of rows : ";
      cin>>num;
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             cout<<"  ";       /* double space*/
         for(int j=1;j<=2*i-1;j++)
      {
             cout<<j<<" ";
      }
        cout<<"\n";
    }
    return 0;
}


Output

Enter number of rows :- 4

1 2 3 4 5 6 7
1 2 3 4 5
1 2 3
1

PROBLEM-18

A B C D E F G
A B C D E
A B C
A

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      char ch;
      for(int i=num;i>=1;i--)
    {
         ch='A';
         for(int space=1;space<num-i;space++)
             printf("  ");       /* double space*/
         for(int j=1;j<=2*i-1;j++)
      {
             printf("%c ",ch);
             ch++;
      }
        printf("\n");
    }
    return 0;
}


#include  <iostream>
using namespace std;
int main()
{
      int num;
      cout<<"enter number of rows : ";
      cin>>num;
      char ch;
      for(int i=num;i>=1;i--)
    {
         ch='A';
         for(int space=1;space<num-i;space++)
             cout<<"  ";       /* double space*/
         for(int j=1;j<=2*i-1;j++)
      {
             cout<<ch<<" ";
             ch++;
      }
        cout<<"\n";
    }
    return 0;
}


Output

Enter number of rows :- 4

A B C D E F G
A B C D E
A B C
A

PROBLEM-19

1 2 3 4 5 6 7
8 9 10 11 12
13 14 15
16

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      int k=1;
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             printf("  ");       /* double space*/
         for(int j=1;j<=2*i-1;j++)
      {
             printf("%d ",k);
             k++;
      }
        printf("\n");
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
      int num;
      cout<<"enter number of rows : ";
      cin>>num;
      int k=1;
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             cout<<"  ";       /* double space*/
         for(int j=1;j<=2*i-1;j++)
      {
             cout<<k<<" ";
             k++;
      }
        cout<<"\n";
    }
    return 0;
}


Output

Enter number of rows :- 4

1 2 3 4 5 6 7
8 9 10 11 12
13 14 15
16

PROBLEM-20

A B C D E F G
H I J K L
M N O
P

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      char ch='A';
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             printf("  ");       /* double space*/
         for(int j=1;j<=2*i-1;j++)
      {
             printf("%c ",ch);
             ch++;
      }
        printf("\n");
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
      int num;
      cout<<"enter number of rows : ";
      cin>>num;
      char ch='A';
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             cout<<"  ";       /* double space*/
         for(int j=1;j<=2*i-1;j++)
      {
             cout<<ch<<" ";
             ch++;
      }
        cout<<"\n";
    }
    return 0;
}


Output

Enter number of rows :- 4

A B C D E F G
H I J K L
M N O
P

PROBLEM-21

1*2*3*4*5*6*7
1*2*3*4*5
1*2*3
1

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             printf("  ");       /* double space*/
         for(int j=1;j<=2*i-1;j++)
      {
             if(j!=1)
             printf("*%d",j);
             else
             printf("%d",j);
      }
        printf("\n");
    }
    return 0;
}


#include  <iostream>
using namespace std;
int main()
{
      int num;
      cout<<"enter number of rows : ";
      cin>>num;
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             cout<<"  ";       /* double space*/
         for(int j=1;j<=2*i-1;j++)
      {
             if(j!=1)
             cout<<"*"<<j;
             else
             cout<<j;
      }
        cout<<"\n";
    }
    return 0;
}


Output

Enter number of rows :- 4

1*2*3*4*5*6*7
1*2*3*4*5
1*2*3
1

PROBLEM-22

A*B*C*D*E*F*G
A*B*C*D*E
A*B*C
A

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      char ch;
      for(int i=num;i>=1;i--)
    {
         ch='A';
         for(int space=1;space<=num-i;space++)
             printf("  ");       /* double space*/
         for(int j=1;j<=2*i-1;j++)
      {
             if(j!=1)
             printf("*%c",ch);
             else
             printf("%c",ch);
             ch++;
      }
        printf("\n");
    }
    return 0;
}


#include  <iostream>
using namespace std;
int main()
{
      int num;
      cout<<"enter number of rows : ";
      cin>>num;
      char ch;
      for(int i=num;i>=1;i--)
    {
         ch='A';
         for(int space=1;space<=num-i;space++)
             cout<<"  ";       /* double space*/
         for(int j=1;j<=2*i-1;j++)
      {
             if(j!=1)
             cout<<"*"<<ch;
             else
             cout<<ch;
             ch++;
      }
        cout<<"\n";
    }
    return 0;
}


Output

Enter number of rows :- 4

A*B*C*D*E*F*G
A*B*C*D*E
A*B*C
A

PROBLEM-23

1*2*3*4*5*6*7
8*9*10*11*12
13*14*15
16

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      int k=1;
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             printf("  ");       /* double space*/
         for(int j=1;j<=2*i-1;j++)
      {
             if(j!=1)
             printf("*%d",k);
             else
             printf("%d",k);
             k++;
      }
        printf("\n");
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
      int num;
      cout<<"enter number of rows : ";
      cin>>num;
      int k=1;
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             cout<<"  ";       /* double space*/
         for(int j=1;j<=2*i-1;j++)
      {
             if(j!=1)
             cout<<"*"<<k;
             else
             cout<<k;
             k++;
      }
        cout<<"\n";
    }
    return 0;
}


Output

Enter number of rows :- 4

1*2*3*4*5*6*7
8*9*10*11*12
13*14*15
16

PROBLEM-24

A*B*C*D*E*F*G
H*I*J*K*L
M*N*O
P

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      char ch='A';
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             printf("  ");       /* double space*/
         for(int j=1;j<=2*i-1;j++)
      {
             if(j!=1)
             printf("*%c",ch);
             else
             printf("%c",ch);
             ch++;
      }
        printf("\n");
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
      int num;
      cout<<"enter number of rows : ";
      cin>>num;
      char ch='A';
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             cout<<"  ";       /* double space*/
         for(int j=1;j<=2*i-1;j++)
      {
             if(j!=1)
             cout<<"*"<<ch;
             else
             cout<<ch;
             ch++;
      }
        cout<<"\n";
    }
    return 0;
}


Output

Enter number of rows :- 4

A*B*C*D*E*F*G
H*I*J*K*L
M*N*O
P

PROBLEM-25

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

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      int k=1;
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             printf("  ");       /* double space*/
         for(int j=1;j<=2*i-1;j++)
      {
             if(i%2!=0)
             printf("0 ");
             else
             printf("1 ");
      }
        printf("\n");
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
      int num;
      cout<<"enter number of rows : ";
      cin>>num;
      int k=1;
      for(int i=num;i>=1;i--)
    {
         for(int space=1;space<=num-i;space++)
             cout<<"  ";       /* double space*/
         for(int j=1;j<=2*i-1;j++)
      {
             if(i%2!=0)
             cout<<"0 ";
             else
             cout<<"1 ";
      }
        cout<<"\n";
    }
    return 0;
}


Output

Enter number of rows :- 4

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