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=1;i<=num;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=1;i<=num;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

1
1 2
1 2 3
1 2 3 4

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      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 ",j);
      }
        printf("\n");
    }
    return 0;
}


#include  <iostream>
using namespace std;
int main()
{
      int num;
      cout<<"enter number of rows : ";
      cin>>num;
      for(int i=1;i<=num;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
1 2
1 2 3
1 2 3 4

PROBLEM-3

A
A B
A B C
A B C D

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      char ch;
      for(int i=1;i<=num;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=1;i<=num;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
A B
A B C
A B C D

PROBLEM-4

1
2 2
3 3 3
4 4 4 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=1;i<=num;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
2 2
3 3 3
4 4 4 4

PROBLEM-5

A
B B
C C C
D D D D

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      char ch='A';
      for(int i=1;i<=num;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=1;i<=num;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
B B
C C C
D D D D

PROBLEM-6

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=1;i<=num;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=1;i<=num;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-7

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=1;i<=num;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=1;i<=num;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
B C
D E F
G H I J

PROBLEM-8

0
1 1
0 0 0
1 1 1 1

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      int k=1;
      for(int i=1;i<=num;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=1;i<=num;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
1 1
0 0 0
1 1 1 1

PROBLEM-9

1
2 4
1 3 5
2 4 6 8

Code


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


Output

Enter number of rows :- 4

1
2 4
1 3 5
2 4 6 8

PROBLEM-10

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

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      for(int i=1;i<=num;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=1;i<=num;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
1*2
1*2*3
1*2*3*4

PROBLEM-11

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

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      char ch;
      for(int i=1;i<=num;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=1;i<=num;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
A*B
A*B*C
A*B*C*D

PROBLEM-12

1
2*2
3*3*3
4*4*4*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++)
      {
             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=1;i<=num;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
2*2
3*3*3
4*4*4*4

PROBLEM-13

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

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      char ch='A';
      for(int i=1;i<=num;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=1;i<=num;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*B
C*C*C
D*D*D*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=1;i<=num;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=1;i<=num;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=1;i<=num;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=1;i<=num;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=1;i<=num;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=1;i<=num;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
1 2 3
1 2 3 4 5
1 2 3 4 5 6 7

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      for(int i=1;i<=num;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=1;i<=num;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
1 2 3
1 2 3 4 5
1 2 3 4 5 6 7

PROBLEM-18

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

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      char ch;
      for(int i=1;i<=num;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=1;i<=num;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
A B C
A B C D E
A B C D E F G

PROBLEM-19

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

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      int k=1;
      for(int i=1;i<=num;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=1;i<=num;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

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=1;i<=num;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=1;i<=num;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
1*2*3
1*2*3*4*5
1*2*3*4*5*6*7

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      for(int i=1;i<=num;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=1;i<=num;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
1*2*3
1*2*3*4*5
1*2*3*4*5*6*7

PROBLEM-22

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

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      char ch;
      for(int i=1;i<=num;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=1;i<=num;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
A*B*C
A*B*C*D*E
A*B*C*D*E*F*G

PROBLEM-23

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

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      int k=1;
      for(int i=1;i<=num;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=1;i<=num;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

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=1;i<=num;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=1;i<=num;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
1 1 1
0 0 0 0 0
1 1 1 1 1 1 1

Code


#include <stdio.h>
int main()
{
      int num;
      printf("enter number of rows : ");
      scanf(" %d",&num);
      int k=1;
      for(int i=1;i<=num;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=1;i<=num;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
1 1 1
0 0 0 0 0
1 1 1 1 1 1 1