Header Ads

Equilateral Triangle Printing In C

 Equilateral Triangle Printing In C
A triangle with all sides equal is called equilateral triangle. We shall now see how to print stars *, in an equilateral triangle shape.
In geometry, an equilateral triangle is a triangle in which all three sides are equal. In the familiar Euclidean geometry, equilateral triangles are also equiangular; that is, all three internal angles are also congruent to each other and are each 60°. They are regular polygons and can therefore also be referred to as regular triangles.
Algorithm should like this:
Step 1 - Take number of rows to be printed, n.
Step 2 - Make an iteration for n times
Step 3 - Print " " (space) for in decreasing order from 1 to n-1
Step 4 - Print "* " (start, space) in increasing order
Step 5 – Return

Example #1: Check Armstrong Number of three digits
#include <stdio.h>
int main() {
   int n,i,j;
// number of rows.
printf(“Enter  number of rows you want to print: ”);
Scanf(“%d”,n);
   for(i = 1; i <= n; i++) {
      for(j = 1; j <= n-i; j++)
         printf(" ");
      for(j = 1; j <= i; j++)
         printf("* ");
      printf("\n");
   }
   return 1;
}
Output:



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



Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Powered by Blogger.