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

C++ Lec-2 Introduction to Object-Oriented Programming (OOP) in C++

  Introduction to Object-Oriented Programming (OOP) in C++ Object-Oriented Programming (OOP) is a programming paradigm that uses objects and classes to organize software design. It allows for modelling real-world entities and relationships in a program. C++ is an object-oriented programming language that provides features to implement OOP concepts effectively. Key Concepts of OOP   Class and Object o    Class : A blueprint for creating objects. It defines properties and behaviours of objects.   class Car { public:     string brand;     string model;     int year; };   o    Object : An instance of a class.   Car car1; car1.brand = "Mahindra"; car1.model = "THAR"; car1.year = 2024;   Encapsulation o    Encapsulation is the bundling of data and methods that operate on that data within a single unit, or class. It restricts direct acces...

C++ Lec-1 (Introduction to Programming Languages)

  Introduction to Programming Languages ________________________________________________________________________ P rogramming languages are formal languages comprising a set of instructions that produce various kinds of output. They are used in computer programming to implement algorithms and control the behavior of machines. Language Generation Programming languages have evolved through several generations: First Generation (1GL) : Machine language, the most basic level of programming languages, consisting of binary code. Second Generation (2GL) : Assembly language, a low-level language with a strong correspondence to the machine language instructions. Third Generation (3GL) : High-level languages like C, C++, Java, Python, which are more abstract and easier for humans to understand. Fourth Generation (4GL) : Languages closer to human language, often used for database querying and report generation (e.g., ...

DATA TYPE in C/C++

  BUILT IN OF PRIMARY DATA TYPE     int (Integer) float(Floating-point) double (Double Floating-point) char (Character) wchar_t (Wide Character) bool (Boolean) void (Empty) Modified Data Types List    signed int - (used for integers) unsigned - int (can only store positive integers) short (used - for small integers (range -32768 to 32767)) unsigned short - (used for small positive integers (range 0 to 65,535)) Long - (used for large integers) unsigned long - (used for large positive integers ) long long - (used for very large integers) unsigned long long - (used for very large positive integers) long double - (used for large floating-point numbers) signed char - (used for characters (guaranteed range -127 to 127)) unsigned char - (used for characters (range 0 to 255)) Derived Type Data Type    Function Array Pointers References User-Defined Data Type   Class Structure Union Enumeration Typedef defined DataType