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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site