Print Patterns in C : part 2


Levels of difficulty: / perform operation:

Patterns Part 1
Patterns Part 2
Patterns Part 3
Patterns Part 4
Patterns Part 5


Output : 11

    1    
   1 2   
  1 2 3  
 1 2 3 4 
1 2 3 4 5_

Program : 11

#include <stdio.h>
#include <conio.h>
void main() {
	int rw,c,no,spc;
	clrscr();
	printf("Enter number of rows : ");
	scanf("%d", &no);
	for (rw=1; rw<=no; rw++) {
		for (spc=no; spc>=rw; spc--) {
			printf(" ");
		}
		for (c=1; c<=rw; c++) {
			printf("%2d",c);
		}
		printf("\n");
	}
	getch();
}





Output : 12

        1    
      1 2 3
    1 2 3 4 5
  1 2 3 4 5 6 7
1 2 3 4 5 6 7 8 9_

Program : 12

#include <stdio.h>
#include <conio.h>
void main() {
	int i,j,k;
	clrscr();
	for (i=1; i<=5; i++) {
		for (j=1; j<=5-i; j++) {
			printf("   ");
		}
		for (k=1; k<=2*i-1; k++) {
			printf(" %d ",k);
		}
		printf("\n");
	}
	getch();
}





Output : 13

 A B C D E F G G F E D C B A
   A B C D E F F E D C B A
     A B C D E E D C B A
       A B C D D C B A
         A B C C B A
           A B B A
             A A_

Program : 13

#include <stdio.h>
#include <conio.h>
void main() {
	int i,j,asci,spc;
	clrscr();
	for (i=7; i>=1; i--) {
		for (spc=6; spc>=i; spc--) {
			printf("  ");
		}
		asci=65;
		for (j=1; j<=i; j++) {
			printf("%2c",asci++);
		}
		for (j=i-1; j>=0; j--) {
			printf("%2c",--asci);
		}
		printf("\n");
	}
	getch();
}





Output : 14

AAA AAB AAC ABA ABB ABC ACA ACB ACC BAA BAB BAC BBA BBB
BBC BCA BCB BCC CAA CAB CAC CBA CBB CBC CCA CCB CCC_

Program : 14

#include <stdio.h>
#include <conio.h>
void main() {
	char ch1, ch2, ch3;
	clrscr();
	for (ch1='A' ; ch1<='C' ; ++ch1) {
		for (ch2='A' ; ch2<='C' ; ++ch2) {
			for (ch3='A' ; ch3<='C' ; ++ch3) {
				printf(" %c%c%c", ch1, ch2, ch3);
			}
		}
	}
	getch();
}





Output : 15

11111
2222
333
44
5

Program : 15

#include <stdio.h>
int main() {
	int i, j;
	for (i=1;i<=5;i++) {
		for (j=5;j>=i;j--) {
			printf("%d",i);
		}
		printf("\n");
	}
	return 0;
}





Output : 16

1234567
12345
123
1

Program : 16

int main() {
	int i,j;
	for (i=7;i>=1;i-=2) {
		for (j=1;j<=i;j++) {
			printf("%d",j);
		}
		printf("\n");
	}
	return 0;
}





Output : 17

55555
45555
34555
23455
12345

Program : 17

int main() {
	int i, j, k;
	for (i=5;i>=1;i--) {
		k = i;
		for (j=1;j<=5;j++) {
			if(k <= 5) {
				printf("%d",k);
			} else {
				printf("5");
			}
			k++;
		}
		printf("\n");
	}
	return 0;
}





Output : 18

1
10
101
1010
10101

Program : 18

#include<stdio.h>
int main() {
	int i,j,k;
	for (i=1;i<=5;i++) {
		for (j=1;j<=i;j++) {
			printf("%d",j%2);
		}
		printf("\n");
	}
	return 0;
}





Output : 19

12344321
123**321
12****21
1******1

Program : 19

#include<stdio.h>

int main() {
	int i,j,k;
	for (i=4;i>=1;i--) {
		for (j=1;j<=4;j++) {
			if(j<=i)
			        printf("%d",j); else
			        printf(" ");
		}
		for (j=4;j>=1;j--) {
			if(j<=i)
			        printf("%d",j); else
			        printf(" ");
		}
		printf("\n");
	}
	return 0;
}





Output : 20

5432*
543*1
54*21
5*321
*4321

Program : 20

#include<stdio.h>

int main() {
	int i,j;
	for (i=1;i<=5;i++) {
		for (j=5;j>=1;j--) {
			if(i==j)
			        printf("*"); else
			        printf("%d",j);
		}
		printf("\n");
	}
	return 0;
}