0

Write a program to print triangle with just​ three sides to print

(with the help of for loop only)there should not be anything inside the triangle just empty space

18th Mar 2017, 12:05 AM
Serjeel Ranjan
Serjeel Ranjan - avatar
2 Réponses
+ 3
#include <iostream> using namespace std; void drawTriangle(char border, char filler, int length) { int start =2; int base =4; int i; for(i=start; i<=length; i++) { for(int sp=0; sp<=length-i; sp++) { cout << " "; } if(i>start) { cout << border<< " "; } if(i>start) { for(int b=base; b<=i; b++) { cout <<filler << " "; } } cout << border << " "; cout <<endl; } for (int j = base; j<length+base; j++) { cout <<border<< " "; } cout << endl; } int main() { int length =12; drawTriangle('*',' ',length); return 0; }
18th Mar 2017, 3:31 AM
ChaoticDawg
ChaoticDawg - avatar
0
Thank You very much
18th Mar 2017, 7:10 AM
Serjeel Ranjan
Serjeel Ranjan - avatar