-->

Write a program to get given pattern

/*WAP to get following
                                  * * * * * 
                        * * * * *
                   * * * * * 
             * * * * *
*/
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,k;
for(i=1;i<=5;i++)      //for number of rows. there are five rows so loop moves fives times
  {
    for(k=8;k>=i;k--)
      {
      printf(" ");   // this part is for space. every time , on display, it decreases space.
      }
    for(j=1;j<=4;j++) //it displays star five times.It displays in columns
      {
 printf("* ");
      }
    printf("\n"););
}
getch();
}
---------------------------
logic in mind:-
----------
it has three parts:
first is number of rows
second part is number of columns
third part decreasing space on each display.
1)fist loop is used for number of rows
2) the inner loop is for space to display
3)the inner most is for star display every time.

Program's screen:-


program's output:


Note:-
From here onward, we are writing program using return and int main().
so using return, it looks like.
#include <stdio.h>
#include<conio.h>
int main()
{
  int i,j,k;
for(i=1;i<=5;i++)      //for number of rows. there are five rows so loop moves fives times
  {
    for(k=8;k>=i;k--)
      {
      printf(" ");   // this part is for space. every time , on display, it decreases space.
      }
    for(j=1;j<=4;j++) //it displays star five times.It displays in columns
      {
 printf("* ");
      }
    printf("\n");
}
   getch();
  return 0;
}
---------------------------------------------------
read me:-

nothing you have to do here. Just put int main() in the beginning and return 0 at the end

No comments:

Post a Comment