NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package main

import "fmt"

type Trec struct {
v1 int
vx struct {
v2, v3 int
}
v4 int
}
type set [2022]int
type settrec [2022]Trec

//1
func BanyakNilai(rec *Trec) {
var v1, v2, v3, v4 int
//menampung nilai awal
v1 = rec.v1
v2 = rec.vx.v2
v3 = rec.vx.v3
v4 = rec.v4
//a) mengubah field v1 menjadi nilai terkecil dari semua field asal
if v1 < v2 && v1 < v3 && v1 < v4 {
rec.v1 = v1
} else if v2 < v1 && v2 < v3 && v2 < v4 {
rec.v1 = v2
} else if v3 < v1 && v3 < v2 && v3 < v4 {
rec.v1 = v3
} else if v4 < v1 && v4 < v2 && v4 < v3 {
rec.v1 = v4
}
//b) mengubah field v2 menjadi jumlah dari semua field asal
rec.vx.v2 = v1 + v2 + v3 + v4
//c) mengubah field v3 menjadi rata-rata dari nilai semua field asal
rec.vx.v3 = (v1 + v2 + v3 + v4) / 4
//d) mengubah field v4 menjadi nilai terbesar dari semua field asal
if v1 > v2 && v1 > v3 && v1 > v4 {
rec.v4 = v1
} else if v2 > v1 && v2 > v3 && v2 > v4 {
rec.v4 = v2
} else if v3 > v1 && v3 > v2 && v3 > v4 {
rec.v4 = v3
} else if v4 > v1 && v4 > v2 && v4 > v3 {
rec.v4 = v4
}
}

//2
func TambahData(tab *set, n *int) {
//input data ke array
var temp int
fmt.Scan(&temp)
for temp != 9999 {
tab[*n] = temp
*n++
fmt.Scan(&temp)
}
}

//3
func CariSekuensial(tab set, n, v int) int {
//mencari lokasi v di array tab
var cek bool
var i int
cek = false
i = 0
for i < n && !cek {
cek = tab[i] == v
i++
}
if cek {
return i - 1
} else {
return -1
}
}

//4
func NilaiMinimum(tab set, n int) int {
//mencari lokasi nilai terkecil
var i, min int
min = 0
i = 0
for i < n {
if tab[i] < min {
min = tab[i]
}
i++
}
return i - 1
}

//5
func NilaiRerata(tab set, n int) int {
//mencari nilai rerata dari semua nilai
var i, jumlah int
jumlah = 0
for i < n {
jumlah = jumlah + tab[i]
i++
}
return jumlah / n
}

//6
func TerurutA(tab *set, n int) {
//mengurutkan array dari yang terkecil hingga terbesar
var idx, temp, i, pass int
pass = 1
for pass <= n-1 {
idx = pass - 1
i = pass
for i <= n-1 {
if tab[idx] > tab[i] {
idx = i
}
i++
}
temp = tab[pass-1]
tab[pass-1] = tab[idx]
tab[idx] = temp
pass++
}
}

//7
func TerurutB(tab *set, n int) {
//mengurutkan array dari yang terbesar hingga terkecil
var i, j, temp int
i = 1
for i < n {
temp = tab[i]
j = i
for j != 0 && temp > tab[j-1] {
tab[j] = tab[j-1]
j--
}
tab[j] = temp
i++
}
}

//8
func CariCepat(tab set, n, v int) int {
//mencari lokasi v dalam array yang terurut mengecil menggunakan binary search
var left, right, mid, found int
left = 1
right = n - 1
found = -1
for left <= right && found == -1 {
mid = (left + right) / 2
if v > tab[mid] {
right = mid - 1
} else if v < tab[mid] {
left = mid + 1
} else {
found = mid
}
}
return found
}

//9
func Shaggy(tab settrec, n int) {
var i int
var found1, found2, found bool
found = false
i = 2
for i < n && !found {
found1 = (tab[i-1].v1 == tab[i].vx.v2)
found2 = (tab[i].vx.v3 == tab[i].v4)
found = found1 && found2
i++
}
if found {
println("Ada Shaggy disana. Yaitu ...?")
}
}

func main() {
var tab set
var rec Trec
var n int
n = 0
//1
BanyakNilai(&rec)
//2
TambahData(&tab, &n)
//3
CariSekuensial(tab, n, v)
//4
//5
//6
//7
//8
}
     
 
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.