Answer to Question #26625 in C# for bryan
2013-03-17T02:29:09-04:00
design a program that will display the odd numbers in pyramid form
1
2013-03-19T10:32:50-0400
#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 !
Learn more about our help with Assignments:
C#
Comments
Leave a comment