NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

Week 5
package main

import "fmt"

func main(){
var rows int
var temp int = 1
fmt.Print("Enter number of rows : ")
fmt.Scan(&rows)

for i := 1; i <= rows; i++ {

for k := 1; k <= i; k++ {

fmt.Printf(" %d",temp)
temp++
}
fmt.Println("")
}

}

Week 7
package main

import (
"fmt"
"strings"
)

func main() {
var originalString string
fmt.Print("Enter a string: ")
fmt.Scanln(&originalString)

var reverseString string
length := len(originalString)

for i := length - 1; i >= 0; i-- {
reverseString += string(originalString[i])
}

if strings.ToLower(originalString) == strings.ToLower(reverseString) {
fmt.Println("The given string is a Palindrome")
} else {
fmt.Println("The given string is NOT a Palindrome")
}
}

Week 4
package main
import (
"fmt"
"math"
)
func main(){
var num[10] float64
var sum,mean,sd float64
fmt.Println("Enter 5 element")
for i := 1; i <= 5; i++ {
fmt.Printf("Enter %d element : ",i)
fmt.Scan(&num[i-1])
sum += num[i-1]
}
mean = sum/10;

for j := 0; j < 5; j++ {
sd += math.Pow(num[j] - mean, 2)
}

sd = math.Sqrt(sd/5)

fmt.Println("The Standard Deviation is : ",sd)
}

Week 6
package main

import "fmt"

func main() {
fmt.Print("Enter First String: ") //Print function is used to display output in same line
var first string
fmt.Scanln(&first) // Take input from user
fmt.Print("Enter Second String: ")
var second string
fmt.Scanln(&second)
fmt.Print(first + second) // Addition of two string
}

Week 3
go mod init family
Main.go
package main

import (
parent "family/father"
child "family/father/son"

"fmt"
)

func main() {
f := new(parent.Father)
fmt.Println(f.Data("Mr. Jeremy Maclin"))

c := new(child.Son)
fmt.Println(c.Data("Riley Maclin"))
}
Father.go
package father

import "fmt"

func init() {
fmt.Println("Father package initialized")
}

type Father struct {
Name string
}

func (f Father) Data(name string) string {
f.Name = "Father : " + name
return f.Name
}

son.go
package son

import "fmt"

func init() {
fmt.Println("Son package initialized")
}

type Son struct {
Name string
}

func (s Son) Data(name string) string {
s.Name = "Son : " + name
return s.Name
}

Week 2
package main

import "fmt"

func main() {
var rows,k,temp,temp1 int
fmt.Print("Enter number of rows :")
fmt.Scan(&rows)

for i := 1; i <= rows; i++ {

for j := 1; j <= rows-i; j++ {
fmt.Print(" ")
temp++
}
for{
if( temp <= rows-1){
fmt.Printf(" %d",i+k)
temp++
}else{
temp1++
fmt.Printf(" %d",(i+k-2*temp1))
}
k++

if(k == 2*i-1){
break
}

}
temp = 0
temp1 = 0
k = 0
fmt.Println("")
}

}

Week 1
package main
import "fmt"

/* Function without return declaration*/
func lcm(temp1 int,temp2 int) {
var lcmnum int =1
if(temp1>temp2) {
lcmnum=temp1
}else{
lcmnum=temp2
}
/* Use of For Loop as a While Loop*/
for {
if(lcmnum%temp1==0 && lcmnum%temp2==0) { // And operator
/* Print Statement with multiple variables */
fmt.Printf("LCM of %d and %d is %d",temp1,temp2,lcmnum)
break
}
lcmnum++
}
return // Return without any value
}

func gcd(temp1 int,temp2 int){
var gcdnum int
/* Use of And operator in For Loop */
for i := 1; i <=temp1 && i <=temp2 ; i++ {
if(temp1%i==0 && temp2%i==0) {
gcdnum=i
}
}
fmt.Printf("GCD of %d and %d is %d",temp1,temp2,gcdnum)
return
}


func main() {
var n1,n2,action int
fmt.Println("Enter two positive integers : ")
fmt.Scanln(&n1)
fmt.Scanln(&n2)

fmt.Println("Enter 1 for LCM and 2 for GCD")
fmt.Scanln(&action)
/* Use of Switch Case in Golang */
switch action {
case 1:
lcm(n1,n2)
case 2:
gcd(n1,n2)
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.