Print various different Pattern: C Program

0
36

These program prints various different patterns of numbers and stars. These codes illustrate how to create various patterns using c programming. Most of these c programs involve usage of nested loops and space. A pattern of numbers, star or characters is a way of arranging these in some logical manner or they may form a sequence. Some of these patterns are triangles which have special importance in mathematics. Some patterns are symmetrical while other are not. Please see the complete page and look at comments for many different patterns.

[message_box title=”Program 1″ color=”red”]

/* Print a Pattern */

/* Written by Utpal Chaudhary */

/*Student of L.D COLLEGE OF ENGINEERING,Ahmedabad-15,Gujarat */

#include <stdio.h>
#include <conio.h>

void main()
{
int n, c, k;
clrscr();

printf(“Enter number of rows\n”);
scanf(“%d”,&n);

for ( c = 1 ; c <= n ; c++ )
{
for( k = 1 ; k <= c ; k++ )
printf(“*”);

printf(“\n”);
}

getch();
}

[/message_box]

[message_box title=”Output” color=”red”]

Enter number of rows

5

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

[/message_box]

Consider the Pattern

[message_box title=”pyramid” color=”yellow”]

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

[/message_box]

We have shown five rows above, in the program you will be asked to enter the numbers of rows you want to print in the pyramid of stars.

[message_box title=”Program 2″ color=”red”]

/* print pyramid of stars */

/*written by Utpal Chaudhary */

#include <stdio.h>

#include <conio.h>

void main()

{

int row, c, n, temp;

clrscr();

  printf(“Enter the number of rows in pyramid of stars you wish to see “);

 scanf(“%d”,&n);

temp = n;

  for ( row = 1 ; row <= n ; row++ )

{

for ( c = 1 ; c < temp ; c++ )

printf(” “);

temp–;

for ( c = 1 ; c <= 2*row – 1 ; c++ )

printf(“*”);

  printf(“\n”);

}   getch();

}

[/message_box]

Using these examples you are in a better position to create your desired pattern for yourself. Creating a pattern involves how to use nested loops properly, some pattern may involve alphabets,numbers or other special characters. Key aspect is knowing how the characters in pattern changes.

Pattern

[message_box title=”” color=”yellow”]

        1
       232
      34543
     4567654
    567898765

[/message_box]

[message_box title=”Program 3″ color=”red”]

#include<stdio.h>
#include<conio.h> 
 void main()
{
      int n, c, d, num = 1, space;
 
      scanf("%d",&n);
 
      space = n - 1;
 
      for ( d = 1 ; d <= n ; d++ )
      {
          num = d;
 
          for ( c = 1 ; c <= space ; c++ )
              printf(" ");
 
          space--;
 
          for ( c = 1 ; c <= d ; c++ )
          {
              printf("%d", num);
              num++;
          }
          num--;
          num--;
          for ( c = 1 ; c < d ; c++)
          {
              printf("%d", num);
              num--;
          }
          printf("\n");
 
      }
 
      getch();
}

[/message_box]

SHARE
Previous articleAN IR LED
Next articleIC 4510
I am third year student of computer engineering in L.D COLLEGE OF ENGINEERING,Ahmedabad.

Leave a Reply

Be the First to Comment!

Notify of
wpDiscuz