Star triangle
Given n, print i stars (*) on the i-th line (1 ≤ i ≤ n).
- Input
- 1 ≤ n ≤ 50
- Output
- n lines
3
* ** ***
Given n, print i stars (*) on the i-th line (1 ≤ i ≤ n).
3
* ** ***
When you run, these lines are fed to input()/stdin in order (the program doesn't stop to ask).
$ Ready
Open this on a computer to write and run code. On mobile you can read the problem and the solutions.
Repeating a character differs by language: Python "*" * i, JavaScript/Java "*".repeat(i), C# new string('*', i), C++ std::string(i, '*').
C has none, so it uses a nested loop.
Craykon grows the line with + "*".
n = int(input())for i in range(1, n + 1): print("*" * i)const n = Number(require("fs").readFileSync(0, "utf8"));for (let i = 1; i <= n; i++) console.log("*".repeat(i));import { readFileSync } from "node:fs";const n: number = Number(readFileSync(0, "utf8"));for (let i = 1; i <= n; i++) console.log("*".repeat(i));import java.util.Scanner; public class Main { public static void main(String[] args) { int n = new Scanner(System.in).nextInt(); for (int i = 1; i <= n; i++) System.out.println("*".repeat(i)); }}using System; class Program{ static void Main() { int n = int.Parse(Console.ReadLine()); for (int i = 1; i <= n; i++) Console.WriteLine(new string('*', i)); }}#include <iostream>#include <string> int main() { int n; std::cin >> n; for (int i = 1; i <= n; i++) std::cout << std::string(i, '*') << '\n';}#include <stdio.h> int main(void) { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { for (int j = 0; j < i; j++) putchar('*'); putchar('\n'); } return 0;}n = Console.ReadLine().ToNumber();line = "";for (i = 1; i <= n; i++){ line = line + "*"; Console.WriteLine(line);}