top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Print a Equilateral Triangle of length n using C?

+4 votes
286 views
Print a Equilateral Triangle of length n using C?
posted Jan 5, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

/* C program to print Equilateral Triangle*/

#include<stdio.h>
main()
{
      int i,j,k,n;

      printf("Enter number of rows  of the triangle \n");
      scanf("%d",&n);

      for(i=1;i<=n;i++)
      {
              for(j=1;j<=n-i;j++)
              {
                      printf(" ");
              }
              for(k=1;k<=(2*i)-1;k++)
              {
                      printf("*");
              }
              printf("\n");
      }
      getch();
}
answer Jan 5, 2016 by Mohammed Hussain
0 votes
#include<stdio.h>
#include<stdlib.h>
int main()
{
      int i,j,k,n;
      printf("Enter the number of rows of the triangle \n");
      scanf("%d",&n);

      for(i=1;i<=n;i++)
      {
              for(j=1;j<=n-i;j++)
              {
                      printf(" ");
              }
              for(k=1;k<=(2*i)-1;k++)
              {
                      printf("*");
              }
              printf("\n");
      }
      getch();
}
answer Mar 9, 2016 by Ashish Kumar Khanna
Similar Questions
+2 votes

Input:
arr = {'a', 'b'}, length = 3

Output:
aaa
aab
aba
abb
baa
bab
bba
bbb

–1 vote

Floyd's triangle is a right-angled triangular array of natural numbers, used in computer science education. It is named after Robert Floyd. It is defined by filling the rows of the triangle with consecutive numbers, starting with a 1 in the top left corner.
Please help me how should i print the following pattern using c language.

1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

+4 votes

Say you are given a 2X2 board then number of squares are 5. Can someone help with the logic and sample program?

...