Right-Angled Star Triangle
Print a right-angled triangle of stars with n rows (row i has i stars).
Sample input
5
Sample output
*
**
***
****
*****
Solution
n = 5
for i in range(1, n + 1):
print("*" * i)
const n = 5;
for (let i = 1; i <= n; i++) {
console.log("*".repeat(i));
}
public class Main {
public static void main(String[] args) {
int n = 5;
for (int i = 1; i <= n; i++) {
StringBuilder row = new StringBuilder();
for (int j = 0; j < i; j++) row.append("*");
System.out.println(row.toString());
}
}
}
fun main() {
val n = 5
for (i in 1..n) {
println("*".repeat(i))
}
}
let n = 5
for i in 1...n {
print(String(repeating: "*", count: i))
}
void main() {
int n = 5;
for (int i = 1; i <= n; i++) {
print('*' * i);
}
}
#include <iostream>
using namespace std;
int main() {
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < i; j++) cout << "*";
cout << endl;
}
return 0;
}
#include <stdio.h>
int main() {
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < i; j++) printf("*");
printf("\n");
}
return 0;
}