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=i;space<num;space++)
             printf("  ");       /* double space*/
          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=i;space<num;space++)
             cout<<"  ";       /* double space*/
         for(int j=1;j<=i;j++)
      {
             cout<<"* ";
      }
        cout<<"\n";
    }
    return 0;
}


Output

Enter number of rows :- 4

* * * *
  * * *
    * *
      *

PROBLEM-2

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=i;space<num;space++)
             printf("  ");       /* double space*/
         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=i;space<num;space++)
             cout<<"  ";       /* double space*/
         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-3

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=i;space<num;space++)
             printf("  ");       /* double space*/
         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=i;space<num;space++)
             cout<<"  ";       /* double space*/
         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-4

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=i;space<num;space++)
             printf("  ");       /* double space*/
         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=i;space<num;space++)
             cout<<"  ";       /* double space*/
         for(int j=1;j<=i;j++)
      {
             cout<<a<<" ";
      }
         a++;
        cout<<"\n";
    }
    return 0;
}


Output

1 1 1 1
  2 2 2
    3 3
      4

PROBLEM-5

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=i;space<num;space++)
             printf("  ");       /* double space*/
         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=i;space<num;space++)
             cout<<"  ";       /* double space*/
         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-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=num;i>=1;i--)
    {
         for(int space=i;space<num;space++)
             printf("  ");       /* double space*/
         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=i;space<num;space++)
             cout<<"  ";       /* double space*/
         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=num;i>=1;i--)
    {
         for(int space=i;space<num;space++)
             printf("  ");       /* double space*/
         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=i;space<num;space++)
             cout<<"  ";       /* double space*/
         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