Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- const int size = 4;
- int linearSearch(char[], char&, int);
- int main()
- {
- char name[] = { 'J', 'u', 'a', 'n' };
- char letter;
- for (int i = 0; i < size; i++)
- {
- cout << name[i] << " ";
- }cout << endl;
- cout << "Find a letter of the name :"; cin >> letter;
- int x=linearSearch(name, letter, size);
- if (x == -1)
- {
- cout << "Not found !" << endl;
- }else
- {
- cout << "Letter found!" << endl;
- cout << "Letter :" << letter << endl;
- cout << "Position :" << x << endl;
- }
- return 0;
- }
- int linearSearch(char list[], char& letter, int size)
- {
- int posi;
- for (int i = 0; i < size; i++)
- {
- if (list[i] == letter)
- {
- return posi = i;
- }
- }
- return posi = -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement