pattern programs in c | print half pyramid, pyramid, inverted pyramid, Pascal's Triangle and Floyd's triangle in C Programming by techwithcode

In this article, TechWithCode is going to provide the full concepts of How to write a C program for all patterns one by one.
Today we will draw the following different types of patterns using the number, star (*), and alphabets using C programming:
With the help of this Logic, you can also print these Pattern in Cpp, Python, JAVA, and Many programming Languages

  1. Half pyramid
  2. Pyramid
  3. Inverted pyramid
  4. Diamond
  5. Pascal's Triangle
  6. Swastika pattern
  7. Floyd's triangle and many more..

1. Program in c of pattern Half pyramid

This is  a C Program sourse code of Half Pyramid Pattern. when you run this code it will ask you how many numbers of the row you want to print. It will print the of the row as per you entered during the run time.

  • The output of programs in c of Half pyramid 

pattern programs in c | print half pyramid, pyramid, inverted pyramid, Pascal's Triangle and Floyd's triangle in C Programming by techwithcode

2. Programs in c of pattern Pyramid 

This is a C Program source code of Pyramid Pattern. when you run this code it will ask you how many numbers of the row you want to print. It will print the row as you entered during the run time.

  • the output of pattern programs in c of Pyramid

pattern program in c,c programming,pattern programs in c,pattern in c,pattern program,pattern printing,pattern in c programming,c pattern programs,pattern printing in c programming,patterns in c,diamond pattern in c,star pattern,* pattern programs in c,pattern programs,number pattern program in c,string pattern program in c,techwithcode.com

3. Programs in c of pattern Inverted pyramid

This is a C Program source code of Inverted Pyramid Pattern. when you run this code it will ask you how many numbers of the row you want to print. It will print the row as you entered during the run time.

  • The output of  C programs of pattern Inverted pyramid

pattern program in c,c programming,pattern programs in c,pattern in c,pattern program,pattern printing,pattern in c programming,c pattern programs,pattern printing in c programming,patterns in c,diamond pattern in c,star pattern,* pattern programs in c,pattern programs,number pattern program in c,string pattern program in c,techwithcode.com


4. Programs in c of pattern Diamond

The diamond pattern in C programming can be printed by two methods. The first method to print a diamond pattern is by without using recursion and the Second method is by using recursion.
Here I am using the first method that means without recursion to print the diamond pattern using the * Star symbol.

  • Code to print Diamond in C programming.



The output of  C programs of pattern Diamond

pattern program in c,c programming,pattern programs in c,pattern in c,pattern program,pattern printing,pattern in c programming,c pattern programs,pattern printing in c programming,patterns in c,diamond pattern in c,star pattern,* pattern programs in c,pattern programs,number pattern program in c,string pattern program in c,techwithcode.com

5.pattern programs in c of Pascal's Triangle


  • Programs in c of pattern Pascal's Triangle using *
This is a C Program source code of  Pascal's Triangle Pattern. when you run this code it will ask you how many numbers of the row you want to print. It will print the row as you entered during the run time.


  • Output of  C programs of pattern Pascal's Triangle

pattern program in c,c programming,pattern programs in c,pattern in c,pattern program,pattern printing,pattern in c programming,c pattern programs,pattern printing in c programming,patterns in c,diamond pattern in c,star pattern,* pattern programs in c,pattern programs,number pattern program in c,string pattern program in c,techwithcode.com

6.pattern programs in c of Floyd's triangle


  • Programs in c of pattern Floyd's triangle using *
This is a C Program source code of Floyd's triangle Pattern. when you run this code it will ask you how many numbers of the row you want to print. It will print the row as you entered during the run time.


  • Output of  C programs of pattern Floyd's triangle

pattern program in c,c programming,pattern programs in c,pattern in c,pattern program,pattern printing,pattern in c programming,c pattern programs,pattern printing in c programming,patterns in c,diamond pattern in c,star pattern,* pattern programs in c,pattern programs,number pattern program in c,string pattern program in c,techwithcode.com

7.pattern programs in c of Swastika

*       * * * * 
*       *       
*       *       
* * * * * * *
         *       * 
         *       * 
* * * *       *
This is a C Program source code of Swastika Pattern. when you run this code it will ask you how many numbers of the row you want to print. It will print the row as you entered during the run time.
  • Programs in c of pattern Swastika using *
#include<stdio.h>
int main() {
  int n;
  scanf("%d",&n);
  
  for(int i=1;i<=n;i++)
  {
    for(int j=1;j<=n;j++)
    {
    if(i==1)
    {
      if(j>(n/2)||j==1)
      printf("* ");
      else
      printf("  ");
    }
    else if(i==n)
    {
      if(j<=(n/2+1)||j==n)
      printf("* ");
      else
      printf("  ");
    }
    else if(i==(n+1)/2)
     printf("* ");

    else if(i<=n/2&&i!=1)
    {
      if(j==1||j==(n+1)/2)
      printf("* ");
      else
       printf("  ");
    }
    else
    {
      if(j==n||j==(n+1)/2)
      printf("* ");
      else
       printf("  ");
    }
    }  
     printf("\n");
  }
  return 0;
}


8.pattern programs in c of the following pattern


5       5
54     45
543   345
5432 2345
543212345
5432 2345
543   345
54     45
5       5

  • Programs in c of the above pattern
This is a C Program source code of the above pattern Pattern. when you run this code it will ask you how many numbers of the row you want to print. It will print the row as you entered during the run time.

#include <stdio.h>
int main() 
{
  int i,j,n;
  scanf("%d",&n);

  for(i=n;i>=1;i--) {
    for(j=n;j>=1;j--) {
      if(j>=i)
        printf("%d",j);
      else
        printf(" ");
    }
    for(j=2;j<=n;j++) {
      if(j>=i)
        printf("%d",j);
      else
        printf(" ");
    }
    printf("\n");
  }

//down
  for(i=2;i<=n;i++) {
    for(j=n;j>=1;j--) {
      if(j>=i)
        printf("%d",j);
      else
        printf(" ");
    }
    for(j=2;j<=n;j++) {
      if(j>=i)
        printf("%d",j);
      else
        printf(" ");
    }
    printf("\n");
  }
}

9.pattern programs in c of the following pattern

1
8 2
14 9 3
19 15 10 4
23 20 16 11 5
26 24 21  17 12 6
28 27 25 22 18 13 7

  • Programs in c of the above pattern
This is a C Program source code of the above pattern Pattern. when you run this code it will ask you how many numbers of the row you want to print. It will print the row as you entered during the run time.

#include<stdio.h>
int main() {

int n,i,j,k,l=1,d;
    scanf("%d",&n);
    for(i=0;i<n;++i)
    {
        for(j=i-1;j>=0;--j)
        {
            d=n-1;
            l=i+1;
            for(k=0;k<=j;++k)
            {
                l+=d;
                d--;
            }
            printf("%d ",l);
        }
        printf("%d\n",i+1);
    }
    return 0;
}


10. Pattern programs in c of the following pattern

1
3 2
4 5 6
10 9 8 7
11 12 13 14 15
21 20 19 18 17 16

  • Programs in c of the above pattern

#include<stdio.h>
int main()
 { 
    int i,j,k,l,n;

    scanf("%d",&n);

     for(k=i=1;i<=n;i++) 
    {
        l=k+i-1
        for(j=1;j<=i;j++)
       { 
            if(i%2==1)
                printf("%d ",k);
            else 
                printf("%d ",l); 
            k++;
            l--;
        }
        printf("\n"); 
    }
     return 0
}

Note:-  More Patterns will be added in the future, so keep visiting this page. If you want to add some pattern program or you want to share your technical skill with us please contact us

Final Word:-

In this article, We have explained to you how to write a C program to print multiple patterns. We hope you like it

If This post helps you a little bit then please share this post with your friends. For more Computer and programming Related Tips and tricks, please

Follow us on Facebook
Subscribe us on Youtube
Follow us on Instagram
Follow us on Pinterest
follow us on Telegram

Don't forget to share how you like this Content in the comment below. If you have any doubt or suggestion then please write in the comment section below, we will love to hear from you.

                               Thank you.

                                        ( नमस्ते )

                                     🙏 


No comments:

Powered by Blogger.