-->

Write a program to get following numeric pattern.

/*Write a program to get following numeric pattern.
0
01
012
0123                                                                                                                    
012
01
0
*/
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,j;
for(i=0;i<=3;i++)
{
 for(j=0;j<=i;j++)
   {
      printf("%d",j);

   }
      printf("\n");
}
for(i=2;i>=0;i--)
{
 for(j=0;j<=i;j++)
   {
      printf("%d",j);

   }
      printf("\n");
}
getch();
}
-------------------------------------------------
logic in mind:-
1) we have to display given pattern.It has two parts
      first part is:upper part .i..e
        0
       01
       012
        0123   
  and second part is
     012
     01
     0
2)for first part, like shown below, we use loop to fetch value from outer loop and displaying from inner loop
3)for second part, we use once again loop with one less value. We fetch that and display from inner loop
just look down.

program's screenshot:

----------------------------
output screen:



No comments:

Post a Comment