Right Triangle a.k.a Segi Tiga Siku-Siku in C


  • Eri
  • erial˳newtimesroman[~@t~]gmail[~d.t~]com
  • Saturday, January 2nd, 2010
  • CopyLEFT (c) 2011++ www.spyrozone.net All Rights Reserved


Kasus: Buatlah sebuah program dengan C/C++ yang menampilkan output segi tiga siku-siku seperti berikut:

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

Penyelesaian:

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
void eri_banner()
{
 printf("             ±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±\n");
 printf("             ±                                                ±\n");
 printf("             ± Right Triangle a.k.a Segi Tiga Siku-Siku in C  ±\n");
 printf("             ±                By: Eri                         ±\n");
 printf("             ±                                                ±\n");
 printf("             ±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±\n");
}
void main()
{
 int x,y,max;
 char lagi='y';
 while((lagi == 'y') || (lagi == 'Y'))
 {
 eri_banner();
 printf("\n\2 Enter Max: ");
 scanf("%d", &max);
 puts("");
 for (x=0;x<max;x++)
 {
 //loop kecil menentukan banyak segitiga perbaris
 for (y=0;y<=x;y++)
 {
 printf("* ");
 }
 printf("\n");
 }
 fflush(stdin);
 printf("\nTry again [y/n]? ");
 scanf("%c", &lagi);
 system("cls");
 puts("");
 }
 getch();
}

Output:

Segi Tiga Siku-Siku

Segi Tiga Siku-Siku


//E.O.F