shape

how can i do this shape
if user enter 5 the output will be
........5
......45
....345
..2345
12345
Last edited on
What have you written so far?

Make sure your code is [code]between code tags[/code] so that it has line numbers and syntax highlighting, as well as proper indentation.
........5
......45
....345
..2345
12345
What code have you written so far?

What specifically are you stuck on or confused with?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
int main()
{
    int val=0;
    if((std::cin >> val) && (val == 5))
    {
        std::cout << "....5" << std::endl;
        std::cout << "...45" << std::endl;
        std::cout << "..345" << std::endl;
        std::cout << ".2345" << std::endl;
        std::cout << "12345" << std::endl;
    }
    return 0;
}
How common is it to have the std::cin inside of the if statement rather than before?
It's more common with other kinds of input streams. In this case, having the input operation as part of the condition means that the if statement will evaluate to false if you type something that isn't a number. More detail:
http://www.lb-stuff.com/user-input
Topic archived. No new replies allowed.