0
someone could help me I have to make a z with the numbers 1-10 in the program in c ++
9 Answers
+ 1
This does something like what you need but not exactly as the output you show..but... best i could do.
#include <iostream>
#include <iomanip> // needed for the setw()
using namespace std;
int main()
{
int width = 4;
for(unsigned int x = 1; x < 11; x++){
if(x < 5 || x > 8)
cout << x;
else
cout << endl << setw(width--) << x;
}
return 0;
}
+ 1
Looking at the output of your code, it seems you need more than 1-10 to output a complete a letter Z here.
How you decide the width and height of the letter Z? does it depend on user input?
+ 1
I'll try something out, I'll get back to you if I can work something out. In the meantime, you keep trying okay?
0
no, the program as such is just printing a "z" from 1 to 10, the width and height I decide
0
Look at this please
12345
6
7
8
910111213
This is what I figure of a letter Z, but it takes more than 1-10, as we put 5 numbers as width, and also 5 numbers as height. If we use 1-10 then there will be only 2 numbers at the floor (9 and 10).
I still don't know how to figure this out TBH : )
0
1234
5
6
78910
Thus reducing size is a z of 1-10. I was doing it with the for cycle, but I don't know how to give the spaces to accommodate the numbers that are impregnated
0
Ok. Thank you
0
Well, this one works particularly for number 1-10. I still haven't figured out a way to calculate the width & height, so I hard coded them as `size` in code. Maybe you can improve from this.
#include <iostream>
int main()
{
int size {4}, padding {2};
int n {10};
for (int i {1}; i <= n; i++)
{
if (i <= size || i > n - size)
{
std::cout << i;
if (i == size) std::cout << std::endl;
}
else
{
for (int p {0}; p < padding; p++)
{
std::cout << " ";
}
std::cout << i << std::endl;
padding--;
}
}
return 0;
}
0
Thank you