Print Patterns in C : part 1

Print Patterns in C : part 1

Output : 1

 * * * * *
* * * * *
* * * * *
* * * * *
* * * * *_

Program : 1

  1. #include <stdio.h>
  2. #include <conio.h>
  3. void main() {
  4. int i,j;
  5. clrscr();
  6. for (i=0; i<5; i++) {
  7. for (j=0; j<5; j++) {
  8. printf(" * ");
  9. }
  10. printf("\n");
  11. }
  12. getch();
  13. }


Output : 2

 * 
* *
* * *
* * * *
* * * * *_

Program : 2

  1. #include <stdio.h>
  2. #include <conio.h>
  3. void main() {
  4. int i,j;
  5. clrscr();
  6. for (i=0; i<5; i++) {
  7. for (j=0; j<=i; j++) {
  8. printf(" * ");
  9. }
  10. printf("\n");
  11. }
  12. getch();
  13. }


Output : 3

         *
* *
* * *
* * * *
* * * * *_

Program : 3

  1. #include <stdio.h>
  2. #include <conio.h>
  3. void main() {
  4. int i,j,k;
  5. clrscr();
  6. for (i=1; i<=5; i++) {
  7. for (j=5; j>=i; j--) {
  8. printf(" ");
  9. }
  10. for (k=1; k<=i; k++) {
  11. printf("*");
  12. }
  13. printf("\n");
  14. }
  15. getch();
  16. }


Output : 4

 * * * * *
* * * *
* * *
* *
*_

Program : 4

  1. #include <stdio.h>
  2. #include <conio.h>
  3. void main() {
  4. int i,j,k,samp=1;
  5. clrscr();
  6. for (i=5; i>=1; i--) {
  7. for (k=samp; k>=0; k--) {
  8. printf(" ");
  9. // only 1 space
  10. }
  11. for (j=i; j>=1; j--) {
  12. printf("*");
  13. }
  14. samp = samp + 1;
  15. printf("\n");
  16. }
  17. getch();
  18. }


Output : 5

 * * * * *
* * * *
* * *
* *
*_

Program : 5

  1. #include <stdio.h>
  2. #include <conio.h>
  3. void main() {
  4. int i,j;
  5. clrscr();
  6. for (i=5; i>=1; i--) {
  7. for (j=1; j<=i; j++) {
  8. printf(" * ");
  9. }
  10. printf("\n");
  11. }
  12. getch();
  13. }


Output : 6

     *
* *
* * *
* * * *
* * * * *_

Program : 6

  1. #include <stdio.h>
  2. #include <conio.h>
  3. void main() {
  4. int i,j,k,t=0;
  5. clrscr();
  6. for (i=1; i<=5; i++) {
  7. for (k=t; k<5; k++) {
  8. printf(" ");
  9. }
  10. for (j=0; j< i; j++) {
  11. printf(" * ");
  12. t = t + 1;
  13. }
  14. printf("\n");
  15. }
  16. getch();
  17. }


Output : 7

         *
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*_

Program : 7

  1. #include <stdio.h>
  2. #include <conio.h>
  3. void main() {
  4. int i,j,k,samp=1;
  5. clrscr();
  6. for (i=1; i<=5; i++) {
  7. for (k=samp; k<=5; k++) {
  8. printf(" ");
  9. }
  10. for (j=0; j< i; j++) {
  11. printf("*");
  12. }
  13. samp = samp + 1;
  14. printf("\n");
  15. }
  16. samp = 1;
  17. for (i=4; i>=1; i--) {
  18. for (k=samp; k>=0; k--) {
  19. printf(" ");
  20. }
  21. for (j=i; j>=1; j--) {
  22. printf("*");
  23. }
  24. samp = samp + 1;
  25. printf("\n");
  26. }
  27. getch();
  28. }


Output : 8

Enter number of rows: 5

1
2 3
4 5 6
7 8 9 10
11 12 13 14 15_

Program : 8

  1. #include <stdio.h>
  2. #include <conio.h>
  3. void main() {
  4. int rw, c, no=1 ,len;
  5. clrscr();
  6. printf("Enter number of rows: ");
  7. scanf("%d," &len);
  8. for (rw=1; rw<=len; rw++) {
  9. printf("\n");
  10. for (c=1; c<=rw; c++) {
  11. printf(" %2d ", no);
  12. no++;
  13. }
  14. }
  15. getch();
  16. }


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

  1. #include <stdio.h>
  2. #include <conio.h>
  3. void main() {
  4. int no,i,y,x=35;
  5. clrscr();
  6. printf("Enter number of rows: ");
  7. scanf("%d," &no);
  8. for (y=0;y<=no;y++) {
  9. goto(x,y+1);
  10. for (i=0-y; i<=y; i++) {
  11. printf(" %3d ", abs(i));
  12. x=x-3;
  13. }
  14. }
  15. getch();
  16. }


Output : 10

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

Program : 10

  1. #include <stdio.h>
  2. #include <conio.h>
  3. void main() {
  4. int i, j=5, k, x;
  5. clrscr();
  6. for (i=1;i<=5;i++) {
  7. for (k=1;k<=j;k++) {
  8. printf(" ");
  9. }
  10. for (x=1;x<=i;x++) {
  11. printf("%d",i);
  12. printf(" ");
  13. }
  14. printf("\n");
  15. j=j-1;
  16. }
  17. getch();
  18. }

Comments

Popular posts from this blog

Add two Number

Print Hello Programmer

Pattern in C Part 4