Showing posts with label star triangle. Show all posts
Showing posts with label star triangle. Show all posts

Saturday, October 13, 2012

Star triangle frame pyramid

Q. Write a C program to print the following star structure
or
Q. Write a C program to print a triangle star frame.

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

Ans.

/*c program for star triangle frame pyramid*/
#include<stdio.h>
int main()
{
 int num,r,j,sp;
 printf("Enter no of rows: ");
 scanf("%d", &num);
 printf("\n*\n");
 for(r=1; r<=num; r++)
 {
  printf("*");
  for(sp=1; sp<r; sp++)
    printf(" ");
  printf("*\n");
 }
 for(j=1; j<=num+2; j++)
   printf("*");
 return 0;
}

The output of above program would be:


Output of star triangle frame pyramid C program
Figure: Screen shot for star triangle frame pyramid C program

Sunday, September 4, 2011

Star (*) Praymid

Q. Write a C program to print the following triangle:







*








* * *






* * * * *




* * * * * * *


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




Ans.

 /*c program for star pyramid*/
 #include<stdio.h>
 #include<conio.h>

 int main()
 {
  int num=6,r,c,sp;

  for(r=1; num>=r; r++)
  {
   for(sp=num-r; sp>=1; sp--)
       printf(" ");
   for(c=r; c>=1; c--)
        printf("*");
   for(c=r; c>1; c--)
        printf("*");
   printf("\n");
  }

  getch();
  return 0; 
 }


/***************OUTPUT***************








*








***






*****




*******


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



***************************************/