Answer to Question #254441 in C++ for heikie

Question #254441

How will the C++ program would look like if we create a UDF that will prompt the user to input the size of the figure (5-15) odd numbers only and display the figure like this:


Sample Output:

Input size of figure to generate (5 - 15) odd numbers only: 5


# # #

# #

# # # # #

# #

# # #


1
Expert's answer
2021-10-21T16:07:30-0400
#include <iostream>
using namespace std;


int main()
{
   int odd, i, j, k;

   cout << "Input size of figure to generate (5 - 15) odd numbers only: ";
   cin >> odd;

   for(i = 1; i <= odd; i++)
   {
      
      for(k = i; k < odd; k++)
      {
         cout << " ";
      }
      
      for(j = 1; j <= (2 * i - 1); j++)
      {
         cout << "#";
      }


      cout << "\n";
   }


   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 the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS