C program to print a vertical english ruler whose length is given by the user In this source code, i have writena program, using for loops, to print an english ruler whose length is given by the user.
So what i want to know is that is it possible to modify this program, to print the ruler in a more logical way And if so, how can it be done, without applying reculsions ?
This is the program to print ruler vertically.
#include &lt;stdio.h&gt;
int main()
{

    int q, num, x;
    int y, p, n;
    printf( &quot;Enter height of central dashes \n&quot; );
    scanf( &quot;%d&quot;, &amp;n );
    printf( &quot;Enter number of inches \n&quot; );
    scanf( &quot;%d&quot;, &amp;num );
    for( x=0; x &lt; num ; x++ )
    {
    for( q=0; q&lt;n; q++ )
    {
    printf( &quot;-&quot; );
    }
    printf( &quot;%d\n&quot;, x );
    for( p=0; p &lt; n-3; p++ )
    {
    printf(&quot;-&quot;);
    }
    printf( &quot;\n&quot; );
    for( p=0; p &lt; n-2; p++ )
    {
    printf( &quot;-&quot; );
    }
    printf( &quot;\n&quot; );
    for( p=0; p &lt; n-3; p++ )
    {
    printf( &quot;-&quot; );
    }
    printf(&quot;\n&quot;);
    for( p = 0; p &lt; n-1; p++)
    {
    printf( &quot;-&quot; );
    }
    printf( &quot;\n&quot; );
    for( p = 0; p &lt; n-3; p++)
    {
    printf( &quot;-&quot; );
    }
    printf( &quot;\n&quot; );
    for( p = 0; p &lt; n-2; p++)
    {
    printf( &quot;-&quot; );
    }
    printf( &quot;\n&quot; );
    for( p = 0; p &lt; n-3; p++)
    {
    printf( &quot;-&quot; );
    }
    printf( &quot;\n&quot; );
    }
    for( y = 0; y &lt; n; y++ )
    {
        printf( &quot;-&quot; );
    }
    printf( &quot;%d&quot;, x );
    printf( &quot;\n&quot; );
    return 0;
 }
The task you are solving is quite simple. So I don't think there's any great change possible. Here are a few things:

You might want to consider accepting command-line parameters (argc and argv) to determine the number of dashes and the dash height.

Your variables are poorly named, and not initialized. You have not specified an old version of C, so I'm assuming that you can write to at least the 1999 C standard (known as &quot;C99&quot;).

You don't validate your user's input.

You don't need to return 0 from main(). Just &quot;fall off the end&quot; of the function and it will do that automatically.

Your last two calls to printf should be merged.

You might want to write functions (or preprocessor macros) to make the various fractional gradations more clear:
#define DRAW_1_8(HEIGHT) for (int i = 0; i &lt; (HEIGHT) - 3; ++i) printf(&quot;-&quot;)


then your main loop becomes a series of named statements:
for (int inch = 0; inch &lt; length; ++inch) {
    DRAW_INCH(height, inch);
    DRAW_1_8(height);
    DRAW_1_4(height);
    DRAW_1_8(height);
    DRAW_1_2(height);
    DRAW_1_8(height);
    DRAW_1_4(height);
    DRAW_1_8(height);
}
DRAW_INCH(height, length);

This does serve to make the code a bit clearer, but mainly it serves to reduce repetition. I'll bet there were a few mistakes early on as you adjusted all the n - K parameters, and macros or functions address that issue.