Print Patterns in C : part 4


Levels of difficulty: / perform operation:

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


Output : 31

11111
0000
111
00
1

Program : 31

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





Output : 32

1234
2341
3421
4321

Program : 32

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





Output : 33

11111
1   1
1   1
1   1
11111 

Program : 33

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





Output : 34

                  1  
              4   9  16 
         25  36  49  64  81 
    100 121 144 169 196 225 256 
289 324 361 400 441 484 529 576 625

Program : 34

#include<stdio.h>

int main() {
	int i, j, k=1;
	for (i=1;i<=5;i++) {
		for (j=i;j<5;j++) {
			printf("    ");
		}
		for (j=1;j<(i*2);j++) {
			printf("%3d ",k*k);
			k++;
		}
		printf("\n");
	}
	return 0;
}





Output : 35

    1
   123
  12345
 1234567
123456789
 1234567
  12345
   123
    1

Program : 35

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





Output : 36

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

Program : 36

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





Output : 37

*000*000*
0*00*00*0
00*0*0*00
000***000

Program : 37

#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("0");
		}
		printf("\n");
	}
	return 0;
}





Output : 38

4444444
4333334
4322234
4321234
4322234
4333334
4444444

Program : 38

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





Output : 39

1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
6 12 18 24 30 36
7 14 21 28 35 42 49
8 16 24 32 40 48 56 64
9 18 27 36 45 54 63 72 81
10 20 30 40 50 60 70 80 90 100

Program : 39

#include <stdio.h>

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





Output : 40

1
1 1
1 2 1
1 3 3 1 
1 4 6 4 1

Program : 40

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





Quantitative Aptitude
Reasoning
Programming
Interview