Author Topic: Left / Right Aligned Star Pattern  (Read 925 times)

kathir

  • Administrator
  • Sr. Member
  • *****
  • Posts: 283
Left / Right Aligned Star Pattern
« on: June 29, 2011, 03:22:25 pm »
Here is the Turbo C Source code using loops to display left aligned and right aligned star pattern

#include <stdio.h>
#include <conio.h>
#include <process.h>
#include <string.h>


void main()
{
    int i, j, k;
    int n = 0;
    printf("Program for displaying pattern of *.\n");
    printf("Enter the maximum number of *: ");
    scanf("%d", &n);

    printf("\nPattern 1 - Left Aligned:\n");

    for (i = 1; i <= n; i++)
    {
       for (j = 1; j <= i; j++)
          printf("*");
       printf("\n");
   }

    printf("\nPattern 2 - Right Aligned:\n");

    for (i = n; i >= 1; i--)
    {
       for(j = 0; j < n - i; j++)
          printf(" ");
       for (j = 1; j <= i; j++)
          printf("*");
       printf("\n");
    }
    printf("\n");
}


Program for displaying pattern of *.
Enter the maximum number of *: 9

Pattern 1 - Left Aligned:

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

Pattern 2 - Right Aligned:

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

Press any key to continue . . .


 


Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.
Content copyright 2010-2014. Kathiresan. All rights reserved.
This page is using SMF version 2.0.1