Wednesday, June 18, 2014

Triangle Image in C


In this article I will show you how to write a program using C as your programming language to show an image of an triangle. We can accomplish this by using three for looping statement to repeat the display of the asterisk symbol over our screen. The code is very simple to understand and easy to learn from it I hope you will find my work useful.

Thank you very much.



Sample Output of Our Program

Program Listing

#include <stdio.h>
#include  <stdlib.h>

main()
{

int a=0,b=0,c=0,n=15;

printf("\n\n");
printf("\t  TRIANGLE");
printf("\n\n");

for(a=1;a<=n;a++)

      {

              for(c=1;c<=n-a;c++)

              {

                      printf(" ");

              }

              for(b=1;b<=(2*a)-1;b++)

              {

                      printf("*");

              }

              printf("\n");

      }
printf("\n\n");
system("pause");

}





No comments:

Post a Comment