C++ gurus and learners, we program ourselves :P all work is CC licensed

Sunday, November 3

C++ Diamond Printing Program Assignment

A program which takes from user, the input of number of lines and prints a diamond

From Saeed Rehman

Code:
#include 
using namespace std;
int main()
{
 int a, b, c, d, e, f, g;
 cout << "enter num" << endl;
 cin >> a;

 for (b = 1; b <= a; b++)
 {
  for (c = 25 - b; c > 1; c--)
   cout << " ";
  for (d = 2 * b - 1; d >= 1; d--)
   cout << "*";
  cout << endl;

 }
 for (b = a - 1; b >= 1; b--)
 {
  for (c = 25 - b; c > 1; c--)
   cout << " ";
  for (d = 2 * b - 1; d >= 1; d--)
   cout << "*";
  cout << endl;
 }


 return 0;
}

Give a +1 for Saeed in comments and he might become a guest author :)

2 comments :