Skip to content

Instantly share code, notes, and snippets.

@DeclanGas
Created June 23, 2022 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DeclanGas/805e1509310d42ef98fc10e3fef1153f to your computer and use it in GitHub Desktop.
Save DeclanGas/805e1509310d42ef98fc10e3fef1153f to your computer and use it in GitHub Desktop.
#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