Created
June 23, 2022 16:54
-
-
Save DeclanGas/805e1509310d42ef98fc10e3fef1153f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cs50.h> | |
#include <stdio.h> | |
#define NUMBERS_ON_CARD 24 | |
// function prototype | |
bool linear_search(int arr[], int n, int size); | |
// Numbers on bingo card | |
int bingo_card[] = {7, 14, 4, 9, 6, 26, 22, 24, 20, 28, 40, 34, 36, 35, 58, 55, 46, 52, 49, 73, 68, 72, 74, 64}; | |
int main(void) | |
{ | |
// Prompt user for number | |
int number = get_int("Number: "); | |
if (linear_search(bingo_card, number, NUMBERS_ON_CARD)) | |
{ | |
printf("Found your number! Bingo!\n"); | |
} | |
else | |
{ | |
printf("Sorry better luck next time!\n"); | |
} | |
} | |
bool linear_search(int arr[], int number, int size) | |
{ | |
// Complete linear search here, return true if found, false if not found | |
for (int i = 0; i < size; i++) | |
{ | |
if (number == bingo_card[i]) | |
{ | |
return true; | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment