Question
(C++ ) Lottery Winners Modification Modify the program you wrote for Programming Challenge 2 (Lottery Winners) so it performs a binary search instead of a
(C++ )
Lottery Winners Modification Modify the program you wrote for Programming Challenge 2 (Lottery Winners) so it performs a binary search instead of a linear search.
this is my (program challenge 2) :
#include
using namespace std;
//Size as 7 const int size = 7;
//Winning Numbers int arrLottery[size]={13579, 26792, 55555, 62483, 79422, 85647, 93121};
//Linear Search int LinearSearch (int [], int, int);
int main()
{
int target, result;
//Take Inout from User cout<<"Please enter this week's 5-digit winning lottery number: ";
cin>>target;
//Call LinearSearch result = LinearSearch(arrLottery, size, target);
//Element found if (result != -1)
{
cout<<"you have a winning ticket."< } else { //Element NOT found cout<<"You did not win this week."< } cin.get(); cin.get(); return 0; } int LinearSearch (int arrLottery[], int Max, int target) { int index; for (index = 0; index < Max-1; index++) { if (arrLottery[index] == target) return 0; } return -1; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started