C++ bool isUnlucky(int a[ ], int len); Implement a function that determines if t
ID: 3934175 • Letter: C
Question
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.
Explanation / Answer
#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;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.