These program prints various different patterns of numbers and stars.
*
**
***
The C programming code for this Pattern:
#include <stdio.h>
#include <conio.h>
void main()
{
int n, i, j;
clrscr();
printf("Enter number of rows\n");
scanf("%d",&n);
for ( i = 1 ; i <= n ; i++ )
{
for( j = 1 ; j <= i ; j++ )
{
printf("*");
}
printf("\n");
}
getch();
}
Floyd's triangle:
This program prints Floyd's triangle. Number of rows of Floyd's triangle to print is entered by the user. First four rows of Floyd's triangle are as follows:
1
23
456
78910
The C programming code for this Pattern:
#include <stdio.h>
#include <conio.h>
void main()
{
int n, i, j, a = 1;
clrscr();
printf("Enter the number of rows to print\n");
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
for (j = 1; j <= i; j++)
{
printf("%d ",a);
a++;
}
printf("\n");
}
getch();
}
No comments:
Post a Comment