- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Golang Program to Read a Number (n) and Print the Natural Numbers Summation Pattern
Let's suppose the number is: 4
Then, the Summation Patten would be:
1 = 1
1 + 2 = 3
1 + 2 + 3 = 6
1 + 2 + 3 + 4 = 10
Steps
- Take a value from the user and store it in a variable, n.
- Use two for loops where the value of t ranges between the values of 1 and n and the value of i ranges between 1 and t.
- Print the value of i and '+' operator.
- Find the sum of elements in the list.
- Print '=' followed by the total sum.
- Exit.
Example
package main import "fmt" func main(){ var n int fmt.Print("Enter number: ") fmt.Scanf("%d", &n) for t:=1; t<=n; t++{ sum := 0 for i:=1; i<=t; i++{ fmt.Printf("%d ", i) if i < t{ fmt.Printf("+ ") } sum += i } fmt.Printf("= %d\n", sum) } }
Output
Enter number: 6 1 = 1 1 + 2 = 3 1 + 2 + 3 = 6 1 + 2 + 3 + 4 = 10 1 + 2 + 3 + 4 + 5 = 15 1 + 2 + 3 + 4 + 5 + 6 = 21
- Related Articles
- Python Program to Read a Number n and Print the Natural Numbers Summation Pattern
- Golang Program to Print Spiral Pattern of Numbers
- Golang Program to Read a Number (n) and Compute (n+nn+nnn)
- Golang Program to Read Two Numbers and Print their Quotient and Remainder
- Python Program to Read a Number n And Print the Series "1+2+…..+n= "
- Goland Program to Read a Number (n) And Print the Series "1+2+…..+n= "
- Golang Program To Print 8 Star Pattern
- Golang Program To Print Diamond Star Pattern
- Golang Program To Print Square Star Pattern
- Golang Program To Print X Star Pattern
- Golang Program to Print Pyramid Star Pattern
- Golang Program to read and print two-dimensional array
- Golang Program to print a hollow star triangle pattern
- Golang Program to Print an Inverted Star Pattern
- Golang Program to Print Half Diamond Star Pattern

Advertisements