c program to print patterns of numbers and stars
Patterns Part 1
Patterns Part 2
Patterns Part 3
Patterns Part 4
Patterns Part 5
Output : 1
* * * * * * * * * * * * * * * * * * * * * * * * *_
Program : 1
#include <stdio.h>
#include <conio.h>
void main() {
int i,j;
clrscr();
for (i=0; i<5; i++) {
for (j=0; j<5; j++) {
printf(" * ");
}
printf("\n");
}
getch();
}
Output : 2
* * * * * * * * * * * * * * *_
Program : 2
#include <stdio.h>
#include <conio.h>
void main() {
int i,j;
clrscr();
for (i=0; i<5; i++) {
for (j=0; j<=i; j++) {
printf(" * ");
}
printf("\n");
}
getch();
}
Output : 3
*
* *
* * *
* * * *
* * * * *_
Program : 3
#include <stdio.h>
#include <conio.h>
void main() {
int i,j,k;
clrscr();
for (i=1; i<=5; i++) {
for (j=5; j>=i; j--) {
printf(" ");
}
for (k=1; k<=i; k++) {
printf("*");
}
printf("\n");
}
getch();
}
Output : 4
* * * * *
* * * *
* * *
* *
*_
Program : 4
#include <stdio.h>
#include <conio.h>
void main() {
int i,j,k,samp=1;
clrscr();
for (i=5; i>=1; i--) {
for (k=samp; k>=0; k--) {
printf(" ");
// only 1 space
}
for (j=i; j>=1; j--) {
printf("*");
}
samp = samp + 1;
printf("\n");
}
getch();
}
Output : 5
* * * * * * * * * * * * * * *_
Program : 5
#include <stdio.h>
#include <conio.h>
void main() {
int i,j;
clrscr();
for (i=5; i>=1; i--) {
for (j=1; j<=i; j++) {
printf(" * ");
}
printf("\n");
}
getch();
}
Output : 6
*
* *
* * *
* * * *
* * * * *_
Program : 6
#include <stdio.h>
#include <conio.h>
void main() {
int i,j,k,t=0;
clrscr();
for (i=1; i<=5; i++) {
for (k=t; k<5; k++) {
printf(" ");
}
for (j=0; j< i; j++) {
printf(" * ");
t = t + 1;
}
printf("\n");
}
getch();
}
Output : 7
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*_
Program : 7
#include <stdio.h>
#include <conio.h>
void main() {
int i,j,k,samp=1;
clrscr();
for (i=1; i<=5; i++) {
for (k=samp; k<=5; k++) {
printf(" ");
}
for (j=0; j< i; j++) {
printf("*");
}
samp = samp + 1;
printf("\n");
}
samp = 1;
for (i=4; i>=1; i--) {
for (k=samp; k>=0; k--) {
printf(" ");
}
for (j=i; j>=1; j--) {
printf("*");
}
samp = samp + 1;
printf("\n");
}
getch();
}
Output : 8
Enter number of rows: 5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15_
Program : 8
#include <stdio.h>
#include <conio.h>
void main() {
int rw, c, no=1 ,len;
clrscr();
printf("Enter number of rows: ");
scanf("%d," &len);
for (rw=1; rw<=len; rw++) {
printf("\n");
for (c=1; c<=rw; c++) {
printf(" %2d ", no);
no++;
}
}
getch();
}
Output : 9
Enter number of rows: 5
0
1 0 1
2 1 0 1 2
3 2 1 0 1 2 3
4 3 2 1 0 1 2 3 4
5 4 3 2 1 0 1 2 3 4 5_
Program : 9
#include <stdio.h>
#include <conio.h>
void main() {
int no,i,y,x=35;
clrscr();
printf("Enter number of rows: ");
scanf("%d," &no);
for (y=0;y<=no;y++) {
goto(x,y+1);
for (i=0-y; i<=y; i++) {
printf(" %3d ", abs(i));
x=x-3;
}
}
getch();
}
Output : 10
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5_
Program : 10
#include <stdio.h>
#include <conio.h>
void main() {
int i, j=5, k, x;
clrscr();
for (i=1;i<=5;i++) {
for (k=1;k<=j;k++) {
printf(" ");
}
for (x=1;x<=i;x++) {
printf("%d",i);
printf(" ");
}
printf("\n");
j=j-1;
}
getch();
}