Question :
A Bunker array is defined to be an array in which at least one odd number is immediately followed by its square. So {4, 9, 6, 7, 49} is a Bunker array because the odd number 7 is immediately followed by 49. But {2, 4, 9, 3, 15, 21} is not a Bunker array because none of the odd numbers are immediately followed by its square.
Write a function named isBunkerArray that returns 1 if its array argument is a Bunker array, otherwise it returns 0.
If you are programming in Java or C#, the function signature is
int isBunkerArray(int [ ] a)
If you are programming in C or C++, the function signature is
int isBunkerArray(int a[ ], int len) where len is the number of elements in the array.
A Bunker array is defined to be an array in which at least one odd number is immediately followed by its square. So {4, 9, 6, 7, 49} is a Bunker array because the odd number 7 is immediately followed by 49. But {2, 4, 9, 3, 15, 21} is not a Bunker array because none of the odd numbers are immediately followed by its square.
Write a function named isBunkerArray that returns 1 if its array argument is a Bunker array, otherwise it returns 0.
If you are programming in Java or C#, the function signature is
int isBunkerArray(int [ ] a)
If you are programming in C or C++, the function signature is
int isBunkerArray(int a[ ], int len) where len is the number of elements in the array.
public static int
isBunkerFunction(int [] a)
        {
            int rtnVal
= 0;
            for(int i=0;i<a.Length-1;i++)
            {
                if(a[i]%2==1)
                {
                    int n=isSquareNum(a[i]);
                    int nextSq=a[i+1];
                    if(n==nextSq)
                    {
                        rtnVal = 1;
                        break;
                    }
                }
            }
            return rtnVal;
        }
 public  static int isSquareNum(int n)
        {
            return n * n;
        }


 04:41
04:41


 

This comment has been removed by the author.
ReplyDelete