- 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
Found 1082 Articles for Go Programming

1K+ Views
ExamplesInput binary_num = 1010111 => decimal number = 64+0+16+4+2+1 = 87Input binary_num = 10101 => decimal number = 21Approach to solve this problemStep 1: Define a function that accepts a binary number, binary_num, declare decimalNum = 0, index = 0Step 2: Start for loop until binary_num becomes 0.Step 3: Find the remainder of binary_num and divide by 10.Step 4: Calculate the decimal number using decimalNum and remainder*pow(2, index).Step 5: Return decimalNum.ProgramLive Demopackage main import ( "fmt" "math" ) func binaryToDecimal(num int) int { var remainder int index := 0 decimalNum := 0 for num ... Read More

3K+ Views
ExamplesInput arr = [1, 3, 4, 5, 6] => 1+3+4+5+6 = 19Input arr = [5, 7, 8, 9, 1, 0, 6] => 5+7+8+9+1+0+6 = 36Approach to solve this problemStep 1: Define a function that accepts an array.Step 2: Declare a variable, res = 0.Step 3: Iterate the array and add elements to res.Step 4: Return res.ProgramLive Demopackage main import "fmt" func findArraySum(arr []int) int{ res := 0 for i:=0; i

2K+ Views
ExamplesInput num = 1432 => output = 2341Input num = 9878 => output = 8789Input num = 6785 => output = 5876Approach to solve this problemStep 1: Define a function that accepts a number (num); type is int.Step 2: Define res = 0 variable and start a loop until num becomes 0.Step 3: Find remainder = num % 10 and make a number.Step 4: Divide num by 10.Step 5: Return res.ProgramLive Demopackage main import "fmt" func reverseNumber(num int) int { res := 0 for num>0 { remainder := num % 10 res = (res * 10) + remainder num /= 10 } return res } func main(){ fmt.Println(reverseNumber(168)) fmt.Println(reverseNumber(576)) fmt.Println(reverseNumber(12345)) }Output861 675 54321

2K+ Views
ExamplesInput arr = [3, 5, 7, 9, 10, 4] => [4, 10, 9, 7, 5, 3]Input arr = [1, 2, 3, 4, 5] => [5, 4, 3, 2, 1]Approach to solve this problemStep 1: Define a function that accepts an array.Step 2: Start iterating the input array.Step 3: Swap first element with last element of the given array.Step 4: Return array.ProgramLive Demopackage main import "fmt" func reverseArray(arr []int) []int{ for i, j := 0, len(arr)-1; i

4K+ Views
ExamplesInput str = “himalaya” => Reverse String would be like => “ayalamih”Input str = “mountain” => Reverse String would be like => “niatnuom”Approach to solve this problemStep 1: Define a function that accepts a string, i.e., str.Step 2: Convert str to byte string.Step 3: Start iterating the byte string.Step 4: Swap the first element with the last element of converted byte string.Step 5: Convert the byte string to string and return it.ProgramLive Demopackage main import "fmt" func reverseString(str string) string{ byte_str := []rune(str) for i, j := 0, len(byte_str)-1; i < j; i, j = i+1, j-1 { ... Read More

800 Views
Examplesnum = 125 => 1 + 2 + 5 = 8num = 101 => 1 + 0 + 1 = 2num = 151 => 1 + 5 + 1 = 7Approach to solve this problemStep 1: Define a function that accepts numbers(num); type is int.Step 2: Start a true loop until num becomes 0 and define res:=0.Step 3: Find modulo and add to res.Step 4: Divide num by 10.Step 5: Return res.ProgramLive Demopackage main import "fmt" func findDigitSum(num int) int { res := 0 for num>0 { res += num % 10 num /= 10 } return res } func main(){ fmt.Println(findDigitSum(168)) fmt.Println(findDigitSum(576)) fmt.Println(findDigitSum(12345)) }Output15 18 15

2K+ Views
Definition: A palindrome is a number which is similar when read from the front and from the rear.Examplesnum = 121 => Palindromenum = 13131 => Palindromenum = 123 => Not a PalindromeApproach to solve this problemStep 1: Define a function that accepts a numbers(num); type is int.Step 2: Start making the number from the input number.Step 3: If the given number is same as the output number, then return “Palindrome”Step 4: Else, return “Not A Palindrome”ProgramLive Demopackage main import "fmt" func checkPalindrome(num int) string{ input_num := num var remainder int res := 0 for num>0 { ... Read More

4K+ Views
Definition: In a Fibonacci series, the next number would be the summation of its two previous numbers, series starting from 0 and 1.ExamplesPrint a fibonacci series up to num = 10;Series: 1, 2, 3, 5, 8, next is 13 but greater than 10;Approach to solve this problemStep 1: Define a function that accepts a numbers(num) type is int, till then need to print the series.Step 2: Take two initial numbers for the series, i.e., 0 and 1.Step 3: Start a true for loop and declare a third variable to store previous two values.Step 4: Print the summation of two numbers until ... Read More

813 Views
Approach to solve this problemStep 1: Define a function that accepts two numbers, type is int.Step 2: Find b = a + b;Step 3: Then a = b – a and b = b – aProgramLive Demopackage main import "fmt" func swap(a, b int){ fmt.Printf("Before swapping, numbers are %d and %d", a, b) b = a + b a = b - a b = b - a fmt.Printf("After swapping, numbers are %d and %d", a, b) } func main(){ swap(23, 45) swap(56, 100) }OutputBefore swapping, numbers are 23 and 45 After swapping, numbers are 45 and 23 Before swapping, numbers are 56 and 100 After swapping, numbers are 100 and 56

2K+ Views
ExamplesFactorial of 5 = 5*4*3*2*1 = 120Factorial of 10 = 10*9*8*7*6*5*4*3*2*1 =Approach to solve this problemStep 1: Define a function that accepts a number (greater than 0), type is int.Step 2: If the number is 1, then return 1.Step 3: Otherwise, return num*function(num-1).ProgramLive Demopackage main import "fmt" func factorial(num int) int{ if num == 1 || num == 0{ return num } return num * factorial(num-1) } func main(){ fmt.Println(factorial(3)) fmt.Println(factorial(4)) fmt.Println(factorial(5)) }Output6 24 120