diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9a846e5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.exe +linearsearch \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..57c2030 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "algorithm": "cpp" + } +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..05054c5 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: g++ build active file", + "command": "/usr/bin/g++", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}/${fileBasenameNoExtension}" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/linearsearch.cpp b/linearsearch.cpp index 9eb220f..4e49cc6 100644 --- a/linearsearch.cpp +++ b/linearsearch.cpp @@ -1,16 +1,20 @@ #include using namespace std; + int main() { - int sea, c, n=6; - int arr[] = { 12, 35, 69, 74, 165, 54}; - sea=165; + int search, c, n = 6; + int arr[] = { 12, 35, 69, 74, 165, 54 }; + search=165; + for (c = 0; c < n; c++) { - if (arr[c] == sea) { + if (arr[c] == search) { printf("%d is present at location %d.\n", search, c+1); break; } } + if (c == n) printf("%d isn't present in the array.\n", search); + return 0; -} \ No newline at end of file +}