Design a program using a one-dimensional array that demonstrates the concept of linear search. The program will ask the user how many elements to be processed and then the program will ask the user to give a series of numbers and the number to be searched. If the given number will be found from the list the program will display the number and then the exact location where the number is located. The program also will display no number found when the search number is not given from the list.
I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details. If you want to advertise on my website kindly contact me also in my email address also. Thank you.
My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675.
Here in Bacolod I also accepting computer repair, networking and Arduino Project development at a very affordable price.
My personal website is http://www.jakerpomperada.com
Sample Program Output
Program Listing
/* linear_search.go
Author : Mr. Jake Rodriguez Pomperada, MAED-IT
Date : August 1, 2019 Thursday 9:00 PM
Location : Bacolod City, Negros Occidental
Website : http://www.jakerpomperada.com
Emails : jakerpomperada@gmail.com and jake_pomperada@tup.edu.ph
*/
package main
import "fmt"
func main() {
{
var arr [10] int
b := 0
c := 0
pos := 0
num_input := 0
fmt.Print("\n")
fmt.Print("\t\tLinear Search Program in Golang")
fmt.Print("\n\n")
fmt.Printf("\tEnter the array size : ");
fmt.Scanln(&num_input);
fmt.Printf("\n");
for b = 0; b < num_input; b++ {
fmt.Printf("\tEnter Array Element Item No. %d : ",b+1);
fmt.Scanln(&arr[b]);
}
fmt.Printf("\n");
fmt.Printf("\tEnter the number to be search : ")
fmt.Scanln(&num_input)
for b = 0; b < num_input; b++ {
if (arr[b] == num_input) {
c = 1;
pos = b + 1;
break;
}
}
if (c == 0) {
fmt.Printf("\n");
fmt.Printf("\tSorry the number %d is not found from the list.", num_input);
} else {
fmt.Printf("\n");
fmt.Printf("\tThe number %d found at position %d.", num_input, pos);
}
fmt.Print("\n\n")
fmt.Print("\tEnd of Program")
fmt.Print("\n")
}
}
No comments:
Post a Comment