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
# # #
# #
# # # # #
# #
# # #
#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;
}
Comments
Leave a comment