DEV Community

Cover image for How To Print Right Alphabate Triangle in Golang and Javascript.
Kuldeep Singh
Kuldeep Singh

Posted on

How To Print Right Alphabate Triangle in Golang and Javascript.

Hello Guys,
So in this articles we're about to cover up , How to print right triangle in golang and javascript as well.

Flow of the code for both quite similar but for converting an int to character can be different for both languages.

Let me tell you which pattern we're going to print in this article

Pattern

A
B C
D E F
G H I J
K L M N O
P Q R S T U
V W X Y Z [ \

We are about to print this pattern , So without wasting anytime let's start writing code as well

  1. Golang

package main

import "fmt"

func main() {
    temp := 65
    rows := 72
    for i := 65; i <= rows; i++ {
        for j := 66; j <= i; j++ {
            fmt.Printf(" %c", temp)
            temp++
        }
        fmt.Println()
    }
}

Enter fullscreen mode Exit fullscreen mode

Let's Explore code step by step , what we have did in code

  1. We have loaded the package which is main .
  2. importing fmt package which is helping us to print the statement.
  3. We've created main function and then main things comes here
  4. we've created two variables and both are important for the program. temp variable is holding the incremented values and another variable to use as rows.
  5. running the loop , There is main focus we have to do is on loops how they have been running.
  6. here we're using formatter to convert int to character, Formatter is %c

For More Reading you can checkout this
https://kdsingh4.blogspot.com/2021/10/right-triangle-characters-pattern-in.html

Top comments (0)