There is a number N
If N is divided by 7 the remainder is 1, it can be shown as mod operator.
N%7=1
N%9=2
N%11=3
What is N?
Read Answers(12) | 24,504 Views |
Why scope resolution operator (::) cannot be overloaded?
Read Answers(2) | 14,024 Views |
Read Answer(1) | 8,293 Views |
why main method have all needed keyword like public void main?
if i write private in contrast of public then what happen and why?
Read Answers(3) | 5,065 Views |
1-Write a function named isSquare that returns 1 if its integer argumentis a square of some integer, otherwise it returns 0. Yourfunction must not use any function or method (e.g. sqrt)that comes with a runtime library or class library!
The signature of the function is
int isSquare(int n)
Examples:
| if n is | return | reason |
| 4 | 1 | because 4 = 2*2 |
| 25 | 1 | because 25 = 5*5/td> |
| -4 | 0 | because there is no integer that when squared equals -4. (note, -2 squared is 4) |
| 8 | 0 | because the square root of 8 is not an integer. |
| 0 | 1 | because 0 = 0*0 |
Post An Answer | 2,855 Views |
An array is said to be hollow if it contains 3 or more zeros in themiddle that are preceded and followed by the same number of non-zero elements.Furthermore, all the zeroes in the array must be in the middle of the array.Write a function named isHollow that accepts an integer array andreturns 1 if it is a hollow array, otherwise it returns 0.
If you are programming in Java or C#, thefunction signature is
int isHollow(int[ ] a)
If you are programming in C or C++, thefunction signature is
int isHollow(int a[ ], int len) where len is the number of elements in thearray
Examples:
| if the input array is | is hollow? | reason |
| {1,2,0,0,0,3,4} | yes | 2 non-zeros precede and follow 3 zeros in the middle |
| {1,1,1,1,0,0,0,0,0,2,1,2,18} | yes | 4 non-zeros precede and follow the 5 zeros in the middle |
| {1, 2, 0, 0, 3, 4} | no | There are only 2 zeroes in the middle; at least 3 are required |
| {1,2,0,0,0,3,4,5} | no | The number of preceding non-zeros(2) is not equal to the number of following non-zeros(3) |
| {3,8,3,0,0,0,3,3} | no | The number of preceding non-zeros(3) is not equal to the number of following non-zeros(2) |
| {1,2,0,0,0,3,4,0} | no | Not all zeros are in the middle |
| {0,1,2,0,0,0,3,4} | no | Not all zeros are in the middle |
| {0,0,0} | yes | The number of preceding non-zeros is 0 which equals the number of following non-zeros. And there are three zeros “in the middle”. |
Hint: Write three loops. The first counts thenumber of preceding non-zeros. The second counts the number of zeros in themiddle. The third counts the number of following non-zeros. Then analyze theresults.
Post An Answer | 2,213 Views |