64 491
Assignments Done
99,1%
Successfully Done
In September 2018

Answer to Question #26625 in C# for bryan

Question #26625
design a program that will display the odd numbers in pyramid form
Expert's answer
#include <iostream>
#include <iomanip>

using namespace std;

/* The height of the pyramid base */
static const int N = 10;
static const int MAX_N = 10;

/* This value is limited by the console screen width (80) */
static const int MAX_LINE_WIDTH = 76;

int main()
{
int lastNumber = 1;
int numbersPerLine;
int begin, end;

for (int y = 1; y < N; y++)
{
numbersPerLine = (y - 1) * 2 + 1;
begin = (MAX_LINE_WIDTH - numbersPerLine * 4) / 2;
cout << setw(begin) << " ";

for (int n = 0; n < numbersPerLine; n++)
{
cout << setw(4) << lastNumber;
lastNumber += 2;
}
cout << endl;
}
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions