Print Patterns in C : part 3


Levels of difficulty: / perform operation:

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


Output : 21

0 
909 
89098 
7890987 
678909876 
56789098765 
4567890987654 
345678909876543 
23456789098765432 
1234567890987654321

Program : 21

#include<stdio.h>

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





Output : 22

    1
   21
  321
 4321
54321

Program : 22

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





Output : 23

1        1
12      21
123    321
1234  4321
1234554321

Program : 23

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





Output : 24

1
2*2
3*3*3
4*4*4*4
4*4*4*4
3*3*3
2*2
1

Program : 24

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





Output : 25

1
232
45654
78910987

Program : 25

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





Output : 26

11
12 13
13 14 15
14 15 16 17

Program : 26

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





Output : 27

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

Program : 27

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





Output : 28

1
212
32123
4321234

Program : 28

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





Output : 29

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

Program : 29

#include<stdio.h>

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





Output : 30

1
23
345
4567
56789

Program : 30

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





Quantitative Aptitude
Reasoning
Programming
Interview