C bool isUnluckyint a int len Implement a function that det
C++
bool isUnlucky(int a[ ], int len);
Implement a function that determines if the unlucky number 13 appears in an array. The function returns true if 13 appears in the array at least once; otherwise it returns false. Write test code that tests every statement in the function. Use assertions in your test code.
C++
bool isUnlucky(int a[ ], int len);
Implement a function that determines if the unlucky number 13 appears in an array. The function returns true if 13 appears in the array at least once; otherwise it returns false. Write test code that tests every statement in the function. Use assertions in your test code.
bool isUnlucky(int a[ ], int len);
Implement a function that determines if the unlucky number 13 appears in an array. The function returns true if 13 appears in the array at least once; otherwise it returns false. Write test code that tests every statement in the function. Use assertions in your test code.
bool isUnlucky(int a[ ], int len);
Implement a function that determines if the unlucky number 13 appears in an array. The function returns true if 13 appears in the array at least once; otherwise it returns false. Write test code that tests every statement in the function. Use assertions in your test code.
Solution
#include <iostream>
using namespace std;
bool isUnlucky(int a[],int len)
{
for(int i=0;i<len;i++)
{
cout<<\"Loop index \"<<i<<\" having element \"<<a[i]<<endl;
if(a[i]==13)
{
return true;
}
}
return false;
}
int main()
{
int a[] = {1,3,5,6,13,6};
cout<<isUnlucky(a,6)<<endl;
return 0;
}
![C++ bool isUnlucky(int a[ ], int len); Implement a function that determines if the unlucky number 13 appears in an array. The function returns true if 13 appear C++ bool isUnlucky(int a[ ], int len); Implement a function that determines if the unlucky number 13 appears in an array. The function returns true if 13 appear](/WebImages/9/c-bool-isunluckyint-a-int-len-implement-a-function-that-det-1000716-1761515464-0.webp)