

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Questions & Answers
- Python Program to Read a Number n and Print the Natural Numbers Summation Pattern
- Golang Program to Read a Number (n) and Compute (n+nn+nnn)
- Golang Program to Read Two Numbers and Print their Quotient and Remainder
- Golang Program to Print an Inverted Star Pattern
- Find m-th summation of first n natural numbers in C++
- 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= "
- PHP program to print the number pattern
- Program to print a pattern of numbers in C++
- Golang Program to Read Three Digits and Print all Possible Combinations from the Digits
- Golang Program to Print all Numbers in a Range Divisible by a Given Number
- Python program to print a checkboard pattern of n*n using numpy.
- Golang Program to Print the Sum of all the Positive Numbers and Negative Numbers in a List
- Java program to find the sum of n natural numbers
- Program to print ‘N’ alphabet using the number pattern from 1 to n in C++
Advertisements