C program and algorithm to generate a pattern

Algorithm


  1. start
  2. input limit
  3. set i=1 and j=1
  4. repeat step 5 to step 8 until i<=limit otherwise go to step 9
  5. repeat step 6 until j<=i otherwise go to step 7
  6. display *
  7. i++
  8. go to step 4
  9. stop
Program

#include<stdio.h>
#include<conio.h>   //only windows users
void main()
{
int lim,i,j;
printf("\n enter the limit:\t");
scanf("%d",&lim);
for(i=1;i<=lim;i++)
{
printf("\n");
for(j=1;j<=i;j++)
{
printf("*");
}
}
getch();           //only windows users
}

Output

enter the limit: 4
*
**
***
****




No comments:

Post a Comment