Code:
#include <stdio.h>
#include <stdlib.h>
int main ( void )
{
int i, j, val;
printf ( "Enter a number from 1 - 9: " );
/*
** Always check the return value of user input functions.
*/
if ( scanf ( "%d", &val ) != 1 || val < 1 || 9 < val ) {
fprintf ( stderr, "Invalid input\n" );
exit ( EXIT_FAILURE );
}
/*
** Outer loop, determine the number of rows and
** the value to be printed, after printing,
** move to the next line.
*/
for ( i = 1; i <= val; i++ ) {
/*
** Inner loop, print the value i times.
*/
for ( j = 0; j < i; j++ )
printf ( "%d", i );
printf ( "\n" );
}
return EXIT_SUCCESS;
}
-Prelude