This
Post Contains A C Program For Printing Triangle Of Numbers With
Correct Source Code & Output. This Program Is Written, Compiled
& Executed At TurboC/C++3.0 Compiler & Will Help You To
Understand The Concept Of 'For-Loop' & 'Nested Loops' From C
Language. It Is A Well-Structured Program With Proper Comments Which
Provides Step-By-Step Description Of Various Features Of The Language In
A Simple & Easy-To-Understand Way.
# Note : You Can Simply Copy-Paste The Following Program Or Code Into Compiler For Direct Result.
C Program For Printing Triangle Of Numbers.
/* Declaration Of Header Files */
# include < stdio.h >
# include < conio.h >
/* Start Of Main Program */
void main()
{
/* Declaration Of Variables */
int i, j, num;
clrscr();
/* Asking For The Input From User */
printf ( " \n Enter No. : " );
scanf( " %d ", &num );
/* Source Code For Printing Triangle Of Numbers */
for ( i = 1; i <= num; i++ )
{
for ( j = 1; j <= i; j++ )
{
if ( i < 10 )
printf ( " %d ", i );
else
printf ( " %d ", i );
}
printf ( " \n" );
}
getch();
}
/* End Of Main Program */
Output :
# Note : You Can Simply Copy-Paste The Following Program Or Code Into Compiler For Direct Result.
C Program For Printing Triangle Of Numbers.
/* Declaration Of Header Files */
# include < stdio.h >
# include < conio.h >
/* Start Of Main Program */
void main()
{
/* Declaration Of Variables */
int i, j, num;
clrscr();
/* Asking For The Input From User */
printf ( " \n Enter No. : " );
scanf( " %d ", &num );
/* Source Code For Printing Triangle Of Numbers */
for ( i = 1; i <= num; i++ )
{
for ( j = 1; j <= i; j++ )
{
if ( i < 10 )
printf ( " %d ", i );
else
printf ( " %d ", i );
}
printf ( " \n" );
}
getch();
}
/* End Of Main Program */
Output :
No comments:
Post a Comment