#include
#include
int pyramid( int length )
{
clrscr();
int line = 1;
int j = 1, i, k = length;
while( length-- )
{
if( j == 1 )
{
for( i = 1; i <= length + 5; i++ )
printf( "" );
printf( "%d", j++ );printf("\n");
k--;
line++;
}
else if( i % 2 )
{
for( i = 1; i <= length + 5; i++ )
printf( "" );
for( i = 1; i <= line; i++ )
printf( "%d ", ( j++ % 10 ) );
printf( "\n" );
line++;
k--;
}
else
{
for( i = 1; i <= length + 5 ; i++ )
printf( "" );
for( i = 1; i <= line; i++ )
printf( "%d ", ( j++ % 10 ) );
printf( "\n" );
line++;
k--;
}
}
return 0;
}
int main( )
{
clrscr();
int length;
printf( "Enter the list length" );
scanf( "%d", &length );
pyramid( length );
getch( );
return 0;
}
No comments:
Post a Comment