Programs to Print Patterns in C or CPP ( Printing Patterns )

Programs to Print Patterns in C or CPP ( Printing Patterns )



These are programs for printing various different patterns written in C language or C++ language.

These patterns are star patterns and some are character patterns.

Programs to Print Patterns in C or CPP ( Printing Patterns )


Note: The following programs can be used to print as big pattern as you want that is you can vary the inputs according to the requirement and print .

1.Print the pattern ( Language : C )

*
**
***
****
*****

#include <stdio.h>

 int main(void) {
 int n;
 printf("Enter no of rows :");
 scanf("%d",&n);
 for(int i=0;i<n;i++)
 {
 for(int j=0;j<=i;j++)
 {
 printf("*");
 }
 printf("\n");
 }
 return 0;
 }

Programs to Print Patterns in C or CPP ( Printing Patterns )

2. Print the pattern ( Language : C )

        *
      **
    ***
  ****
*****

#include <stdio.h>

int main()
{
int n;
printf("Enter no of rows :");
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
 for(int j=1;j<=n;j++)
{
if (j<=n-i)
      {
         printf(" ");
      }
      else{
        printf("*");
      }
    }
    printf("\n");
  }
  return 0;
}

Programs to Print Patterns in C or CPP ( Printing Patterns )

3.Print the pattern ( Language : C )

     *
   * * 
  * * * 
 * * * *
* * * * *

#include <stdio.h>
int main()
{
  int n;
  printf("Enter no of rows :");
  scanf("%d",&n);
  for(int i=1;i<=n;i++)
  {
     int k=0;
     while(k!=n-i)
      {
         printf(" ");
         k++;
      }
    for(int j=1;j<=2*i-1;j++)
    {
      if (j%2!=0)
      {
     printf("*");
      }
     else
     {
     printf(" ");
     }
    }
    printf("\n");
  }
  return 0;
}

Programs to Print Patterns in C or CPP ( Printing Patterns )

4. Print the pattern ( Language : C )

     A
   B C 
  D E F 
 G H I J
K L M N O


#include <stdio.h>
int main()
{
  int n ,letter=65,l=0;
   printf("Enter no of rows :");
  scanf("%d",&n);
  for(int i=1;i<=n;i++)
  {
     int k=0;
     while(k!=n-i)
      {
         printf(" ");
         k++;
      }
    for(int j=1;j<=2*i-1;j++)
    {
      if (j%2!=0)
      {
     printf("%c", letter++);
      }
     else
     {
     printf(" ");
     }
    }
    printf("\n");
  }
  return 0;
}

Programs to Print Patterns in C or CPP ( Printing Patterns )

5. Print the pattern ( Language : C++ )

     A
   A B 
  A B C  
 A B C D 
A B C D E
 A B C D
  
B C
   A B
    A


#include <iostream>
using namespace std;
int main()
{
    int n;
    cout<<"Enter the no of rows :";
    cin>>n;
for(int i=0;i<=n;i++)
{
    int k=0;
    char let=65;
    while(k!=n-i)
    {
       cout<<" ";
        k++;
    }
    for(int j=0;j<2*i-1;j++)
    {
       
        if(j%2==0)
        cout<<let++;
        else
        cout<<" ";
    }
    cout<<endl;
}
for(int i=1;i<n;i++)
{
    char let=65;
    for(int j=0;j<2*n-i-1;j++)
    {
        if(i%2!=0 && j%2!=0 && j>=i)
        cout<<let++;
        else if(i%2==0 && j%2==0 && j>=i)
        {
            cout<<let++;
        }
        else
        cout<<" ";
    }
    cout<<endl;
}
    return 0;
}

Programs to Print Patterns in C or CPP ( Printing Patterns )


Comments

Popular posts from this blog

Notice Writing Format with Examples ( Notice writing )

CSAB (Fee Refund)

All Derivations of Ray Optics Class 12 ( Ray Optics )

Solid state previous year questions CBSE with answers( One mark)

JEE Mains -Mole Concept and Stoichiometry Previous Year Questions (with Answers)

CSAB 2020 ( CSAB Fee Refund )

Message Writing,Format for message writing

Electrostatics Important Five mark questions with answers for CBSE Class 12 (previous year)

Menu Driven Program For Circular Linked List: creation, traversing, insertion and deletion(Circular Linked List)

Solid state previous year questions CBSE with answers( Two and Three Mark )