Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to print Diamond Pattern in C
Program Description
The Diamond pattern is a combination of simple pyramid pattern and inverted pyramid pattern.
Algorithm
First Row: Display 1 Second Row: Display 1,2,3 Third Row: Display 1,2,3,4,5 Fourth Row: Display 1,2,3,4,5,6,7 Fifth Row: Display 1,2,3,4,5,6,7,8,9 Display the same contents from 4th Row till First Row below the fifth Row.
Example
/* Program to print Diamond Pattern */
#include<stdio.h>
int main(){
int i,j,k;
clrscr();
printf("
");
printf("Diamond Pattern");
printf("
");
printf("
");
for(i = 1;i<=5;i++){
for(j = i;j<5;j++){
printf(" ");
}
for(k = 1;k<(i*2);k++){
printf("%d",k);
}
printf("
");
}
for(i = 4;i>=1;i--){
for(j = 5;j>i;j--){
printf(" ");
}
for(k = 1;k<(i*2);k++){
printf("%d",k);
}
printf("
");
}
getch();
return 0;
}
Output

Advertisements