C Pattern Programming

1. Wap to print following pattern.
$
$ $
$ $ $
$ $ $ $
$ $ $ $ $

#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();
}

2. Wap to print the following pattern.
$ $ $ $ $
$ $ $ $
$ $ $
$ $
$

#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();
}

3. Wap to print following pattern.
$
$ $
$ $ $
$ $ $ $
$ $ $ $ $
$ $ $ $
$ $ $
$ $
$
 

#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();
}

4. Wap to print following pattern.
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

#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();
}

5. Wap to print following pattern.
KodNest Capture
 

#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();
}

6. Wap to print following pattern.
KodNest Capture1 1

#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();
}

7. Wap to print following pattern.
$ $ $ $ $
$ $ $ $ $
$ $ $ $ $
$ $ $ $ $
$ $ $ $ $

#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();
}

8. Wap to print following pattern.
KodNest 2 2

#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();
}

9. Wap to print following pattern.
KodNest 3

#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();
}

10. Wap to print following pattern.
KodNest 4
 

#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();
}

11. Wap to print following pattern.
11111
222
333
44
5

#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;
}

12. Wap to print following pattern.
55555
45555
34555
23455
12345

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;
}

13. Wap to print following pattern.
1
10
101
1010
10101

#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;
}

14. Wap to print following pattern.
12344321
123$$321
12$$$$21
1$$$$$$1

#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;
}

15. Wap to print following pattern.
5432$
543$1
54$21
5$321
$4321

#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;
}

16. Wap to print following pattern.
KodNest 5

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

17. Wap to print following pattern.
KodNest 6

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

18. Wap to print following pattern.
1
2$2
3$3$3
4$4$4$4
4$4$4$4
3$3$3
2$3
1

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

19. Wap to print following pattern.
1
232
45654
78910987

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

20. Wap to print following pattern.
11
12 13
13 14 15
14 15 16 17

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

21. Wap to print following pattern.
KodNest 7

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

22. Wap to print following pattern.
1
212
32123
4321234

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

23.Wap to print following pattern.
1
23
345
4567
56789

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

24. Wap to print following pattern.
11111
0000
111
00
1

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

25. Wap to print following pattern.
1234
2341
3421
4321

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

26. Wap to print following pattern.
11111
1    1
1    1
1    1
11111

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

27. Wap to print following pattern.
KodNest 8

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

28. Wap to print following pattern.
KodNest 9

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

29. Wap to print following pattern.
$111$111$
1$00$11$1
11$1$1$11
111$$$111

#include <stdio.h>
int main() {
	int i,j,k;
	for (i=1;i<=4;i++) {
		for (j=1;j<=9;j++) {
			if(j==i || j==5 || 10-j==i)
			        printf("$"); else
			        printf("1");
		}
		printf("\n");
	}
	return 0;
}

30. Wap to print following pattern.
4444444
4333334
4322234
4321234
4322234
4333334
4444444

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

31. Wap to print following pattern.
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1

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

32. Wap to print following pattern.
1
22
333
4444
55555

#include <stdio.h>
int main()
{
    int i, j, N;
    printf("Enter Number of rows: ");
    scanf("%d", &N);
    for(i=1; i<=N; i++)
    {
        for(j=1; j<=i; j++)
        {
            printf("%d", i);
        }
        printf("\n");
    }
    return 0;
}

33. Wap to print following pattern.
KodNest 15

#include <stdio.h>
int main()
{
    int i, j, N;
    printf("Enter Number of rows: ");
    scanf("%d", &N);
    for(i=1; i<=N; i++)
    {
        // Logic to print spaces
        for(j=i; j<N; j++)
        {
            printf(" ");
        }
        // Logic to print numbers
        for(j=1; j<=i; j++)
        {
            printf("%d", i);
        }
        printf("\n");
    }
    return 0;
}

34. Wap to print following pattern.
11111
222
333
44
5

#include <stdio.h>
int main()
{
    int i, j, N;
    printf("Enter Number of rows: ");
    scanf("%d", &N);
    for(i=1; i<=N; i++)
    {
        // Logic to print numbers
        for(j=i; j<=N; j++)
        {
            printf("%d", i);
        }
        printf("\n");
    }
    return 0;
}

35. Wap to print following pattern.
KodNest 16

#include <stdio.h>
int main()
{
    int i, j, N;
    printf("Enter Number of rows");
    scanf("%d", &N);
    for(i=1; i<=N; i++)
    {
        // Logic to print spaces
        for(j=1; j<i; j++)
        {
            printf(" ");
        }
        // Logic to print numbers
        for(j=i; j<=N; j++)
        {
            printf("%d", i);
        }
        printf("\n");
    }
    return 0;
}

36. Wap to print following pattern.
1
21
321
4321
54321

#include <stdio.h>
int main()
{
    int i, j, N;
    printf("Enter Number of rows: ");
    scanf("%d", &N);
    for(i=1; i<=N; i++)
    {
        // Logic to print numbers
        for(j=i; j>=1; j--)
        {
            printf("%d", j);
        }
        printf("\n");
    }
    return 0;
}

37. Wap to print following pattern.
KodNest 17

#include <stdio.h>
int main()
{
    int i, j, N;
    printf("Enter Number of rows: ");
    scanf("%d", &N);
    for(i=1; i<=N; i++)
    {
        // Logic to print spaces
        for(j=1; j<=N-i; j++)
        {
            printf(" ");
        }
        // Logic to print numbers
        for(j=i; j>=1; j--)
        {
            printf("%d", j);
        }
        printf("\n");
    }
    return 0;
}

38. Wap to print following pattern.
5
54
543
5432
54321

#include <stdio.h>
int main()
{
    int i, j, N;
    printf("Enter Number of rows: ");
    scanf("%d", &N);
    for(i=N; i>=1; i--)
    {
        // Logic to print numbers
        for(j=N; j>=i; j--)
        {
            printf("%d", j);
        }
        printf("\n");
    }
    return 0;
}

39. Wap to print following pattern.
KodNest 18

#include <stdio.h>
int main()
{
    int i, j, N;
    printf("Enter Number of rows: ");
    scanf("%d", &N);
    for(i=N; i>=1; i--)
    {
        // Logic to print spaces
        for(j=1; j<i; j++)
        {
            printf(" ");
        }
        // Logic to print numbers
        for(j=N; j>=i; j--)
        {
            printf("%d", j);
        }
        printf("\n");
    }
    return 0;
}

40. Wap to print following pattern.
1
23
345
4567
56789

#include <stdio.h>
int main()
{
    int i, j, k, N;
    printf("Enter Number of rows: ");
    scanf("%d", &N);
    for(i=1; i<=N; i++)
    {
        k = i;
        // Logic to print numbers
        for(j=1; j<=i; j++, k++)
        {
            printf("%d", k);
        }
        printf("\n");
    }
    return 0;
}

41. Wap to print following pattern.
KodNest 19

#include <stdio.h>
int main()
{
    int i, j, k, N;
    printf("Enter Number of rows: ");
    scanf("%d", &N);
    for(i=1; i<=N; i++)
    {
        k = i;
        // Logic to print spaces
        for(j=i; j<N; j++)
        {
            printf(" ");
        }
        // Logic to print numbers
        for(j=1; j<=i; j++, k++)
        {
            printf("%d", k);
        }
        printf("\n");
    }
    return 0;
}

42. Wap to print following pattern.
1
123
12345
1234567
123456789

#include <stdio.h>
int main()
{
    int i, j, N;
    printf("Enter Number of rows: ");
    scanf("%d", &N);
    for(i=1; i<=N; i++)
    {
        // Logic to print numbers
        for(j=1; j<=(i*2-1); j++)
        {
            printf("%d", j);
        }
        printf("\n");
    }
    return 0;
}

43. Wap to print following pattern.
E
DE
CDE
BCDE
ABCDE

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

44. Wap to print following pattern.
KodNest 10

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

45. Wap to print following pattern.
KodNest 11

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

46. Wap to print Pyramid.
KodNest 12

#include<stdio.h>
#define MAX	5
int main()
{
    int i,j;
    int space=4;
    /*run loop (parent loop) till number of rows*/
    for(i=0;i< MAX;i++)
    {
	    /*loop for initially space, before star printing*/
	    for(j=0;j< space;j++)
	    {
		    printf(" ");
	    }
	    for(j=0;j<=i;j++)
	    {
		    printf("$ ");
	    }
	    printf("\n");
	    space--;	/* decrement one space after one row*/
    }
    return 0;
}

47. Wap to print following pattern.
A
B C
D E F
G H I J
K L M N O

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

48. Wap to print following pattern.
KodNest Capture13

#include <stdio.h>
int main()
{
    int i,j;
    int space=4;
    char CH='A';
    /*Run parent loop*/
    for(i=1; i<=5; i++)
    {
        /*Print space*/
        for(j=1; j<=space; j++)
            printf(" ");
        /*Run loop to print first part of row*/
        for(j=1; j<=i; j++)
            printf("%c",CH+j-1);
        /*Run loop to print second part of row*/
        for(j=i-1; j>=1; j--)
            printf("%c",CH+j-1);
        printf("\n");
        space--;
    }
    return 0;
}

49. Wap to print following pattern.
KodNest 13

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

50. Wap to print following pattern.
KodNest 14

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

 

Related Articles

C Programming

1. Wap to check if the given number is armstrong number or not. #include<stdio.h> #include<conio.h> void main(){ int a,t,l,sum=0; printf(“\nPlease enter your number\n”); scanf(“%d”,&a); t=a;…

Core Java

1. What are primitive types in Java ? byte, short, int, long, float, double, char, boolean… 2. What are tokens? Name the 5 types of tokens available in Java with an example…

New Report

Close