#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int r;
do
{
cout << "Enter size for \"DIAMOND\" (Only +ve ODD Numbers Between 3 & 17)?\t";
cin >> r;
} while (r % 2 == 0 || r < 3);
for (int i = 1; i <= r / 2 + 1; i++)
{
cout << setw(40 - r / 2);
int s = 0;
for (int s = 1; s <= (r / 2 + 1) - i; s++)
cout << " ";
for (int c = 1; c <= 2 * i - 1; c++)
{
if (c <= i)
cout << ++s;
else
cout << --s;
}
cout << "\n";
}
for (int i = r / 2; i >= 1; i--)
{
cout << setw(40 - r / 2);
int s = 0;
for (int s = 1; s <= (r / 2 + 1) - i; s++)
cout << " ";
for (int c = 1; c <= 2 * i - 1; c++)
{
if (c <= i)
cout << ++s;
else
cout << --s;
}
cout << "\n";
}
return 0;
}
OUTPUT
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int size, n = 1, j = 1;
do
{
cout << "Enter size for PATTERN (Only +ve ODD Numbers between 1 & 10)?\t";
cin >> size;
} while (size % 2 == 0 || size < 3);
for (int i = 1; i <= size ; i++)
{
cout << setw(40 - size / 2);
if (i <= size / 2)
{
for (int c = 1; c <= i; c++)
cout << n;
for (int s = 1; s <= size - 2 * i; s++)
cout << " ";
for (int c = 1; c <= i; c++)
cout << n;
n += 2;
}
else if (i==size/2+1)
for (int c = 1; c <= size; c++)
cout << n;
else
{
n -= 2;
for (int c = 1; c <= size-i+1; c++)
cout << n;
for (int s = 1; s <= j; s++)
cout << " ";
j += 2;
for (int c = 1; c <= size-i+1; c++)
cout << n;
}
cout << "\n";
}
return 0;
}
OUTPUT
No comments:
Post a Comment