Home > Backend Development > C++ > Write a program in C language to print diamond pattern

Write a program in C language to print diamond pattern

PHPz
Release: 2023-08-29 14:13:09
forward
1624 people have browsed it

Program Description

The diamond pattern is a combination of a simple pyramid pattern and an inverted pyramid pattern. The Chinese translation of

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.
Copy after login

Example

is:

Example

/* Program to print Diamond Pattern */
#include<stdio.h>
int main(){
   int i,j,k;
   clrscr();
   printf("</p><p>");
   printf("Diamond Pattern");
   printf("</p><p>");
   printf("</p><p>");
   for(i = 1;i<=5;i++){
      for(j = i;j<5;j++){
         printf(" ");
      }
      for(k = 1;k<(i*2);k++){
         printf("%d",k);
      }
      printf("</p><p>");
   }
   for(i = 4;i>=1;i--){
      for(j = 5;j>i;j--){
         printf(" ");
      }
      for(k = 1;k<(i*2);k++){
         printf("%d",k);
      }
      printf("</p><p>");
   }
   getch();
   return 0;
}
Copy after login

Output

Write a program in C language to print diamond pattern

The above is the detailed content of Write a program in C language to print diamond pattern. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template