Skip to main content

Most Asked Pattern Programs in C

 

Pattern Programs in C


 


Source Code Example : 1
int main()
{
 int i,j,a;
 printf("\nEnter the value:");
 scanf("%d",&a);
 for(i=1;i<=a;i++)
 {
    printf("\n");
    for(j=1;j<=i;j++)
    {
      printf("%d",i);
    }
 }
 return 0;
}


Output
Enter the value:5
1
22
333
4444
55555


Source Code Example : 2
#include<stdio.h>
int main()
{
 int i,j,a;
 printf("\nEnter the value:");
 scanf("%d",&a);
 for(i=1;i<=a;i++)
 {
    printf("\n");
    for(j=1;j<=i;j++)
    {
      printf("%d",j);
    }
 }
 return 0;
}


Output
Enter the value:5
1
12
123
1234
12345




Source Code Example : 3
#include<stdio.h>
int main()
{
 int i,j,a,b=1;
 printf("\nEnter the value:");
 scanf("%d",&a);
 for(i=1;i<=a;i++)
 {
    printf("\n");
    for(j=1;j<=i;j++)
    {
      printf(" %d",b);
      b++;
    }
 }
 return 0;
}


Output
Enter the value:5
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15



Source Code Example : 4
#include<stdio.h>
int main()
{
 int i,j,a;
 printf("\nEnter the value:");
 scanf("%d",&a);
 for(i=1;i<=a;i++)
 {
    printf("\n");
    for(j=1;j<=i;j++)
    {
      printf("%d",(i-j+1));
    }
 }
 return 0;
}
Output
Enter the value:5
1
21
321
4321
54321



Source Code Example :5
#include<stdio.h>
int main()
{
 int i,j,a;
 printf("\nEnter the value:");
 scanf("%d",&a);
 for(i=1;i<=a;i++)
 {
   printf("\n");
   for(j=1;j<=(a-i);j++)
   {
     printf(" ");
   }
   for(j=1;j<=i;j++)
   {
    printf("%d",j);
   }
 }
 return 0;
}
Output
Enter the value:5
    1    
   12
  123
1234
12345



Source Code Example :6
#include<stdio.h>
int main()
{
 int i,j,a;
 printf("\nEnter the value:");
 scanf("%d",&a);
 for(i=1;i<=a;i++)
 {
     printf("\n");
     for(j=a-i+1;j>0;j--)
     {
       printf("%d",j);
     }
 }
 return 0;
}
Output
Enter the value:5
54321
4321
321
21
1
 


 
Source Code Example : 7
#include<stdio.h>
int main()
{
 int i,j,a;
 printf("\nEnter the value:");
 scanf("%d",&a);
 for(i=1;i<=a;i++)
 {
    printf("\n");
    for(j=1;j<=i;j++)
    {
      printf(" ");
    }
    for(j=1;j<=(a-i+1);j++)
    {
      printf("%d",j);
    }
 }
 return 0;
}
 
Output
Enter the value:5
12345
1234
  123
   12
    1


 
Source Code Example : 8
#include<stdio.h>
int main()
{
 int i,j,n;
 printf("\nEnter the value :");
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {
    printf("\n");
    for(j=1;j<=(n-i);j++)
    {
        printf("  ");
    }
    for(j=1;j<=i;j++)
    {
        printf(" %d",j);
    }
    for(j=1;j<i;j++)
    {
        printf(" %d",(i-j));
    }
 }
 for(i=1;i<=n;i++)
 {
    printf("\n");
    for(j=1;j<=i;j++)
    {
      printf("  ");
    }
    for(j=1;j<(n-i);j++)
    {
       printf(" %d",j);
    }
    for(j=(n-i);j>0;j--)
    {
       printf(" %d",j);
    }
 }
 return 0;
}


Output
Enter the value: 5
        1
      1 2 1
    1 2 3 2 1
  1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
  1 2 3 4 3 2 1
    1 2 3 2 1
      1 2 1
        1



Source Code Example :10
#include<stdio.h>
int main()
{
 int i,j,n;
 printf("\nEnter the value:");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
    printf("\n");
    for(j=n-i;j<=n;j++)
    {
      printf("%d",j);
    }
 }
 return 0;
}

Output
Enter the value:5
5
45
345
2345
12345

#include<stdio.h>
int main()
{
 int i,j,n;
 printf("\nEnter the value:");
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {
    printf("\n");
    for(j=i;j<=n;j++)
    {
      printf("%d",j);
    }
 }
 return 0;
}     

Output
Enter the value:5
12345
2345
345
45
5


Source Code Example :12
#include<stdio.h>
int main()
{
 int i,j,n;
 printf("\nEnter the value:");
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {
    printf("\n");
    for(j=1;j<=i;j++)
    {
      printf(" ");
    }
    for(j=n;j>=i;j--)
    {
      printf("%d",j);
    }
 }
 return 0;
}

Output
Enter the value:5
54321
5432
  543
   54
    5
Source Code Example : 13
#include<stdio.h>
int main()
{
 int i,j,n;
 printf("\nEnter the value:");
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {
    printf("\n");
   
    for(j=1;j<=n-i;j++)
    {
       printf("  ");
    }
    for(j=n;j>n-i;j--)
    {
       printf(" %d",j);
    }
    for(j=n-i+2;j<n+1;j++)
    {
       printf(" %d",j);
    }
 }
 for(i=1;i<=n;i++)
 {
    printf("\n");
 
    for(j=1;j<=i;j++)
    {
       printf("  ");
    }
    for(j=n;j>i;j--)
    {
       printf(" %d",j);
    }
    for(j=i+2;j<=n;j++)
    {
       printf(" %d",j);
    }
 
 }
 return 0;
}

Output
Enter the value:5
        5
      5 4 5
    5 4 3 4 5
  5 4 3 2 3 4 5
5 4 3 2 1 2 3 4 5
  5 4 3 2 3 4 5
    5 4 3 4 5
      5 4 5
        5


Comments

Popular posts from this blog

Flow Charts - What Is a Flow Chart? When to Use a Flowchart? Flowchart Symbols & Components

  Flow Charts     Flow charts are a useful tool in many situations, as we make a process easy to understand at a glance. Using just a few words and some simple symbols, they show clearly what happens at each stage and how this affects other decisions and actions.   What Is a Flow Chart?     In 1921, the Frank and Lillian presented what was only a "graphic-based method" in a presentation titled: “ Process Charts: First Steps in Finding the One Best Way to do Work ”, to members of the American Society of Mechanical Engineers (ASME). When to Use a Flowchart?     Flowchart is a very simple yet powerful tool to improve productivity in both our personal and work life. Here are some ways flowchart can be helpful:   ·      Document a process ·      Present solution to a problem ·      Brainstorm ideas in a meeting ·      Design an operation system ·    ...

Constructors and Destructors in C++

  Constructors and Destructors in C++ Constructors are special class functions which performs initialization of every object. The Compiler calls the Constructor whenever an object is created. Constructors initialize values to object members after storage is allocated to the object. Whereas, Destructor on the other hand is used to destroy the class object. Following is the syntax of defining a constructor function in a class: class A {  public:      int x;      // constructor      A ()      {          // object initialization      } };   While defining a  constructor  you must remember  that the  name of constructor  will be same as the  name of the class , and    constructor  will never have a return type. Constructors can be defined either inside the class definition or outside class definition us...