- 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 Compute (n+nn+nnn)
Let's read a number, n=5
Then, nn=55 and then nnn=555
res = 5 + 55 + 555 => 615
To read a number (n) and compute (n+nn+nnn), we can take the following
Steps
- Define a variable, n.
- Print a statement to get the number, n.
- Take user input for variable, n.
- Make an expression for (n + nn + nnn).
- Convert the expression into numbers.
- Compute the sum of the expression.
Example
package main import ( "fmt" "strconv" ) func main(){ var n int fmt.Print("Enter value of n: ") fmt.Scanf("%d", &n) t1 := fmt.Sprintf("%d", n) t2 := fmt.Sprintf("+%d%d", n, n) t3 := fmt.Sprintf("+%d%d%d", n, n, n) exp := t1 + t2 + t3 fmt.Println("Expression is: ", exp) n1, _ := strconv.Atoi(t1) n2, _ := strconv.Atoi(t2) n3, _ := strconv.Atoi(t3) fmt.Println("Computed expression is: ", n1+n2+n3) }
Output
Enter value of n: 5 Expression is: 5+55+555 Computed expression is: 615
- Related Articles
- Golang Program to Read a Number (n) and Print the Natural Numbers Summation Pattern
- Python Program to Input a Number n and Compute n+nn+nnn
- 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 make a file read-only
- Golang Program to read and print two-dimensional array
- Python Program to Read a Number n and Print the Natural Numbers Summation Pattern
- Golang Program to Read the Contents of a File
- Golang Program to Create a Class and Compute the Area and Perimeter of a Circle
- Golang Program to Compute the Sum of Diagonals of a Matrix
- Golang Program to Read Two Numbers and Print their Quotient and Remainder
- Golang program to read and print all files from zip file
- Golang Program to toggle the Kth of the given number n.
- Golang Program to read the marks of subjects and display the Grade
- Program to compute Log n in C

Advertisements