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.
Pattern 1:
*
***
*****
*******
*********
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.
C programming code
#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();
}
Pattern 2 :
*
**
***
****
*****
C programming code
#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();
}
Pattern 3:
1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
6 12 18 24 30 36
7 14 21 28 35 42 49
8 16 24 32 40 48 56 64
9 18 27 36 45 54 63 72 81
10 20 30 40 50 60 70 80 90 100
C programming code
#include<stdio.h>
#include<conio.h>
void main()
void main()
{
int i,j;
for(i=1;i<=10;i++)
{
for(j=1;j<=i;j++)
{
printf("%d ",i*j);
}
printf("\n");
}
getch();
}
No comments:
Post a Comment