Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Program to print triangle inside square using * (stars)

Posted By: Molly Torres     Category: C Programming     Views: 42667

WRITE A PROGRAM TO GENERATE FOLLOWING FIGURE OF N LINES.
INPUT N FROM KEYBOARD. consider space in place of line.

* * * * * * *
* * *___* * *
* *______* *
*__________*
* *______* *
* * *___* * *
* * * * * * *

Code for Program to print triangle inside square using * (stars) in C Programming

#include<stdio.h>
#include<conio.h>
    
void main()
{
        int i,n,j,x;
        clrscr();
        printf("\n ENTER A VALUE: ");
        scanf("%d",&i);
        for(n=i;n>0;n--)
        {
            for(j=1;j<=n;j++)
            printf(" * ");
            for(j=i-n;j>=1;j--)
            printf("      ");
            for(x=n;x>=1;x--)
            printf(" * ");
            printf("\n");
        }
        for(n=0;n<i;n++)
        {
            for(j=0;j<=n;j++)
            printf(" * ");
            for(j=i-n;j>=2;j--)
            printf("      ");
            for(x=n;x>=0;x--)
            printf(" * ");
            printf("\n");
        }
            getch();
}


******************* OUTPUT *****************************************

     ENTER A VALUE: 5

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



*********************************************************************
  
Share: 


Didn't find what you were looking for? Find more on Program to print triangle inside square using * (stars) Or get search suggestion and latest updates.

Molly Torres
Molly Torres author of Program to print triangle inside square using * (stars) is from Chicago, United States.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!