- 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
Goland Program to Read a Number (n) And Print the Series "1+2+…..+n= "
Steps
- Take a value from the user and store it in a variable (n).
- Use a for loop where the value of i ranges between the values of 1 and n.
- Print the value of i and '+' operator.
- Find the sum of elements in the list.
- Print '=' followed by the total sum.
- Exit.
Explanation
- User must first enter the value and store it in a variable, n.
- The for loop enables i to range between 1 and n (as n+1 is not included).
- For each iteration, the value of i is printed.
- '+' operator is printed only if i
Example
package main import "fmt" func main(){ var n int fmt.Print("Enter the number: ") fmt.Scanf("%d", &n) sum := 0 for i:=1; i<=n; i++{ fmt.Printf("%d ", i) if i < n{ fmt.Printf("+ ") } sum += i } fmt.Printf("= %d", sum) }
Output
Enter the number: 10 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55
- Related Articles
- Python Program to Read a Number n And Print the Series "1+2+…..+n= "
- Python Program to Read a Number n and Print the Natural Numbers Summation Pattern
- Golang 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)
- Java program to print Fibonacci series of a given number.
- C program to print number series without using any loop
- Java Program to print Number series without using any loop
- Java program to print the fibonacci series of a given number using while loop
- Java program to print a Fibonacci series
- Golang Program to read and print two-dimensional array
- Write a Golang program to print the Fibonacci series
- Program to print ‘N’ alphabet using the number pattern from 1 to n in C++
- Print Number series without using any loop in Python Program
- Python Program for Print Number series without using any loop
- Python Program to Read Two Numbers and Print Their Quotient and Remainder

Advertisements