-->
Showing posts with label star patern. Show all posts
Showing posts with label star patern. Show all posts

WEAP to display following star pattern

/*program to display following

* * * * *
* * * * *
* * * * *
* * * * *
* * * * *

*/
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,j;
for(i=1;i<=5;i++)      //for number of rows. there are five rows so loop moves fives times
  {
    for(j=1;j<=5;j++) //it displays star five times.It displays in columns
      {
printf("* ");
      }
    printf("\n");
}
getch();
}

------------------------------------
logic in mind:-
1)we have to display five rows and five columns.
2) we have used outer loop five times.
3)and inner loop five times.
-------------------------------
 program 's screenshot





output







program to display following numeric pattern.

//program to display following numeric pattern.
//      12345
//      1234
//      123
//      12
//      1
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
for(i=5;i>=1;i--)
  {
     for(j=1;j<=i;j++)
          {
                printf("%d",j);
          }
       printf("\n");
 }
getch();
}
--------------------------------------------------------
logics in mind:
----------------------
1)we have to display 1,2,3,4,5 so we use loop.
 2)since the displays are in repetitive form ,,we set up the loop in nested form such that
        internal loop executes 5 times with display of numbers(above).
3)First loop(outer) takes value 5 and assigns to inner.The inner executes 5 times with display.
4)next time, the outer loop takes the value 4 and transfers to inner loop, it displays again and again.
and it goes on