0% found this document useful (0 votes)
0 views

Go_Programs [Record]

The document outlines seven programming tasks in Go, including generating multiplication tables, calculating the area of rectangles, computing simple and compound interest, finding the largest of three numbers, generating prime numbers, displaying a number pattern, and checking for Armstrong numbers. Each task includes an aim, procedure, and a sample program with successful execution results. The programs demonstrate basic programming concepts such as loops, conditionals, and mathematical calculations.

Uploaded by

techxtream03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Go_Programs [Record]

The document outlines seven programming tasks in Go, including generating multiplication tables, calculating the area of rectangles, computing simple and compound interest, finding the largest of three numbers, generating prime numbers, displaying a number pattern, and checking for Armstrong numbers. Each task includes an aim, procedure, and a sample program with successful execution results. The programs demonstrate basic programming concepts such as loops, conditionals, and mathematical calculations.

Uploaded by

techxtream03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

1.

Multiplication Table
Aim:
To generate and display the multiplication table for a given integer.

Procedure:
• Take an integer input from the user.

• Use a loop to multiply the number from 1 to 10.

• Print the multiplication results in a formatted way.

Program:
package main
import "fmt"
func main(){
var n int
fmt.Print("Enter any Integer Number : ")
fmt.Scan(&n)
i:=1
for {
if(i>10){ break; }
fmt.Println(n," X ",i," = ",n*i)
i++
}
}

Output:

Result:
The program has been successfully executed as expected.
2. Area of a Rectangle
Aim:
To calculate and display the area of a rectangle given its length and breadth.

Procedure:
• Take length and breadth as input.

• Multiply the two values to get the area.

• Print the calculated area.

Program:
package main
import "fmt"
var area int
func main(){
var l,b int
fmt.Print("Enter Length of Rectangle : ")
fmt.Scan(&l)
fmt.Print("Enter Breadth of Rectangle : ")
fmt.Scan(&b)
area = l * b
fmt.Println("Area of Rectangle : ",area)
}

Output:

Result:
The program has been successfully executed as expected.
3. Simple and Compound Interest Calculation
Aim:
To calculate simple interest (SI) and compound interest (CI) for given principal, rate, and time.

Procedure:
• Take principal amount, rate of interest, time, and compound frequency as input.

• Use formulas:

• - SI = (P × R × T) / 100

• - CI = P × (1 + R / (100 × n))^(n × T) - P

• Print the calculated SI and CI.

Program:
package main
import (
"fmt"
"math"
)
func main() {
var principal, rate, time, compoundFreq float64
fmt.Print("Enter Principal Amount: ")
fmt.Scanln(&principal)
fmt.Print("Enter Rate of Interest (in %): ")
fmt.Scanln(&rate)
fmt.Print("Enter Time (in years): ")
fmt.Scanln(&time)
fmt.Print("Enter Number of Times Interest Compounded Per Year (for
CI): ")
fmt.Scanln(&compoundFreq)
simpleInterest := (principal * rate * time) / 100
compoundInterest := principal *
math.Pow((1+(rate/(100*compoundFreq))), compoundFreq*time) - principal
fmt.Printf("\nSimple Interest: %.2f\n", simpleInterest)
fmt.Printf("Compound Interest: %.2f\n", compoundInterest)
}
Output:

Result:
The program has been successfully executed as expected.
4. Finding the Largest Number
Aim:
To determine the largest of three given numbers.

Procedure:
• Take three numbers as input.

• Use conditional statements to compare them.

• Print the largest number.

Program:
package main
import "fmt"
func main() {
var num1, num2, num3 float64
fmt.Print("Enter the first number: ")
fmt.Scanln(&num1)
fmt.Print("Enter the second number: ")
fmt.Scanln(&num2)
fmt.Print("Enter the third number: ")
fmt.Scanln(&num3)
var largest float64
if num1 >= num2 && num1 >= num3 {
largest = num1
} else if num2 >= num1 && num2 >= num3 {
largest = num2
} else {
largest = num3
}
fmt.Printf("The largest number is: %.2f\n", largest)
}

Output:

Result:
The program has been successfully executed as expected.
5. Prime Number Generation
Aim:
To generate and display prime numbers within a given range.

Procedure:
• Set the range (e.g., 2 to 100).
• Use a loop to check each number’s divisibility.
• Print only prime numbers.

Program:
package main
import (
"fmt"
"math"
)
func printPrimeNumbers(num1, num2 int){
for num1 <= num2 {
isPrime := true
for i:=2; i<=int(math.Sqrt(float64(num1))); i++{
if num1 % i == 0{
isPrime = false
break
}
}
if isPrime {
fmt.Printf("%d ", num1)
}
num1++
}
fmt.Println()
}
func main(){
printPrimeNumbers(2, 100)
}

Output:

Result:
The program has been successfully executed as expected.
6. Pattern Display
Aim:
To generate and display the given pattern of numbers.

Procedure:
• Set the number of rows for the pattern.
• Use nested loops to generate and print the pattern.
• Align numbers correctly to form a pyramid.

Program:
package main
import "fmt"
func main() {
var rows, NUM1, NUM2, k int = 5, 0, 0, 0
for i := 1; i <= rows; i++ {
k = 0
for space := 1; space <= rows-i; space++ {
fmt.Print(" ")
NUM1++
}
for {
if k == 2*i-1 {
break
}
if NUM1 <= rows-1 {
fmt.Printf("%d ", i+k)
NUM1++
} else {
NUM2++
fmt.Printf("%d ", (i + k - 2*NUM2))
}
k++
}
NUM2, k, NUM1 = 0, 0, 0
fmt.Println("")
}
}
Output:

Result:
The program has been successfully executed as expected.

7. Armstrong Number checking


Aim:
To determine if a given three-digit number is an Armstrong number.

Procedure:
• Take a three-digit number as input.
• Extract each digit, cube it, and sum them.
• If the sum equals the original number, it's an Armstrong number.

Program:
package main
import "fmt"

func main() {
var number,tempNumber,remainder int
var result int =0
fmt.Print("Enter any three digit number : ")
fmt.Scan(&number)
tempNumber = number
for {
remainder = tempNumber%10
result += remainder*remainder*remainder
tempNumber /=10

if(tempNumber==0){
break
}
}
if(result==number){
fmt.Printf("%d is an Armstrong number.",number)
}else{
fmt.Printf("%d is not an Armstrong number.",number)
}
}

Output:

Result:
The program has been successfully executed as expected.

You might also like