Author Topic: VC++ Diamond Star Pattern using simple for loops  (Read 956 times)

kathir

  • Administrator
  • Sr. Member
  • *****
  • Posts: 283
VC++ Diamond Star Pattern using simple for loops
« on: June 29, 2011, 03:41:42 pm »
#include <iostream>
#include <conio.h>
#include <process.h>
#include <string.h>


void main()
{
    int i, j, k;
    int n = 0;
    std::cout << "Program for displaying pattern of *.\n";
    std::cout << "Enter the maximum number of *: ";
    std::cin >> n;

    std::cout << "\nHere is the Diamond of Stars\n";

    for (i = 1; i <= n; i++)
    {
       for (j = 0; j < (n - i); j++)
          std::cout << " ";
       for (j = 1; j <= i; j++)
          std::cout << "*";
       for (k = 1; k < i; k++)
          std::cout << "*";
       std::cout << "\n";
    }

    for (i = n - 1; i >= 1; i--)
    {
       for (j = 0; j < (n - i); j++)
          std::cout << " ";
       for (j = 1; j <= i; j++)
          std::cout << "*";
       for (k = 1; k < i; k++)
          std::cout << "*";
       std::cout << "\n";
    }
   
    std::cout << "\n";
}




 


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1