Skip to content

Instantly share code, notes, and snippets.

@porimol
Created May 16, 2017 09:27
Show Gist options
  • Save porimol/43b278f04c02e01ca731d330b479b21e to your computer and use it in GitHub Desktop.
Save porimol/43b278f04c02e01ca731d330b479b21e to your computer and use it in GitHub Desktop.
Linear Search Algorithm Implementation Using C++
/**
* @file linear_search.cpp
* @author Porimol Chandro, CSE 32D, World University of Bangladesh(WUB)
* @date 16/05/2017
*
* @brief Linear Search Algorithm Implementation.
*/
#include <iostream>
using namespace std;
int main()
{
int A[25] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
int target = 17, i, output, array_lenght = (sizeof(A) / sizeof(int));
for(i = 0; i < array_lenght; i++){
if(A[i] == target){
output = A[i];
break;
}
}
if(output){
cout << "The value is found.\nThe value is: " << output << endl;
} else{
cout << "The value is not found." << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment