Berikut ini adalah beberapa daftar kodingan logika pemograman bentuk segitiga.
- Segitiga sama sisi :
FOR i = 1 TO n
FOR k=n to i STEP -1
PRINT “ “;
NEXT k
FOR j = 1 TO i
PRINT “* ”;
NEXT j
PRINT “”
NEXT i
END
Output :
*
* *
* * *
* * * *
* * * * *
* * * * * *
- Segitiga sama sisi terbalik ke bawah :
n = 6
FOR i = n TO 1 STEP -1
FOR k=n to i STEP -1
PRINT “ “;
NEXT k
FOR j = i TO 1 STEP -1
PRINT “* ”;
NEXT j
PRINT “”
NEXT i
END
Output :
* * * * * *
* * * * *
* * * *
* * *
* *
*
- Segitiga Siku-siku kanan bawah:
FOR i = 1 TO n
FOR j = 1 TO i
PRINT “*”;
NEXT j
PRINT “ ”
NEXT i
END
Output:
*
**
***
****
*****
******
- Segitiga Siku-siku kanan atas:
FOR i = n TO 1
STEP -1
FOR j = 1 TO 1
STEP -1
PRINT “*”;
NEXT j
PRINT “”
NEXT i
END
Output :
******
*****
****
***
**
*
- Segitiga Siku-siku kiri atas :
n = 6
FOR i = 1 TO n
FOR k=n to i STEP -1
PRINT “ “;
NEXT k
FOR j = 1 TO i
PRINT “*”;
NEXT j
PRINT “”
NEXT i
END
Output :
*
**
***
****
*****
******
- Segitiga Siku-siku kiri bawah :
n=6
FOR i = n TO 1 STEP -1
FOR k=n to i STEP -1
PRINT “ “;
NEXT k
FOR j = i TO 1 STEP -1
PRINT “*”;
NEXT j
PRINT “”
NEXT i
END
Output :
******
*****
****
***
**
*
0 komentar:
Posting Komentar