Use code and output tags for legibility. Format options on the right,
<> for code, [co
de]
your code here [/co
de]. Similarly for output.
Both the source code and output are unreadable without these tags.
Well, this looks like C code rather than C++. If that's what you are required to do, it limits some of the options available. But still the code can be simplified and shortened quite a lot.
First, you can make better use of the formatting options of
printf().
Second, you could use the ternary operator to simplify the code. You might also consider the use of
puts(),
putchar() and
getchar() as alternatives to printf and scanf when dealing with a single character.or a straightforward string.
If you do those things, this block reduces to a single line of code:
1 2 3 4 5 6 7 8
|
if( count > 9 )
{
printf( " %d ", count );
}
else
{
printf( " %d ", count);
}
|
and this reduces to one or two lines depending on taste:
1 2 3 4 5 6 7 8
|
if( n[ i ] >= count )
{
printf( "*" );
}
else
{
printf( " " );
}
|
In the first case above, use a suitable printf format string.
In the second, use the ternary operator.
I got the code down to 25 lines, and that includes several blank lines for readability. (If I scrunch it up until it looks ugly, it's down to 16 lines).
see "conditional operator" on this page:
http://www.cplusplus.com/doc/tutorial/operators/
and printf here
http://www.cplusplus.com/reference/clibrary/cstdio/printf/