Our website is made possible by displaying online advertisements to our visitors.Please consider supporting us by disabling your ad blocker.
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Translate it in your own Language

Print this Job Post

Print Friendly and PDF

Monday, May 12, 2014

C program to print diamond pattern

C programming code
#include <stdio.h>
#include<conio.h> 
void main()
{
  int n, c, k, space = 1;
  printf("Enter number of rows\n");
  scanf("%d", &n);
  space = n - 1;
  for (k = 1; k <= n; k++)
  {
    for (c = 1; c <= space; c++)
    printf(" ");
    space--;
    for (c = 1; c <= 2*k-1; c++)
    printf("*");
    printf("\n");
  }
 space = 1;
 for (k = 1; k <= n - 1; k++)
 {
   for (c = 1; c <= space; c++)
   printf(" ");
   space++;
   for (c = 1 ; c <= 2*(n-k)-1; c++)
   printf("*");
   printf("\n");
  }
 getch();
}
Output of the Program:



No comments:

Post a Comment

Copyright @ CrackMNC 2014-2024
Divas Nikhra Theme by Crack MNC