A MobileNumber is a VIP number if it satisfy the following
conditions.
The operator should be Vodafone.
Atleast one 0 (Zero) should be exist in mobile number.
The number should not end with 8.
The single digit sum of all the digits in the number should
be equal to 9. For example if the number is 9876543210, the
sum is 9+8+7+...+1+0 = 45. Sum of 4+5 = 9.
Write a method:
private boolean isVIPMobileNumber(String mobileNum, String
operator)
mobileNum phone number
operator mobile operator as bsnl, Vodafone
// The prototype in question is not exactly c language. but i tried to provide equivalent solution in c.
int SingleDigitSum(int num)
{
int hund, tens, ones;
int sum = 0;
sum = num;
do
{
hund = sum / 100;
sum = sum % 100;
tens = sum / 10;
ones = sum % 10;
sum = hund + tens + ones;
}
while(sum > 9);
return(sum);
}
boolean isVIPMobileNumber(String mobileNum, String operator)
{
int i, sum=0, zeroCnt=0;
int tens, ones;
boolean retValue = FALSE;
// check for Vodafone operator
if(strcmp("Vodafone", operator) == 0)
{
// validate length of mobile number including NULL
if(strlen(mobileNum) == 11)
{
// check for the number should not end with 8
if(mobileNum[9] != 8)
{
for(i=0; i<10; i++)
{
if(mobileNum[i] == '0') zeroCnt++;
sum += mobileNum[i];
}
// Atleast one 0 (Zero) should be exist in mobile number.
// The single digit sum of all the digits in the number should be equal to 9.
// maximum sum possible single digit sum = 9+9+9+9+9+9+9+9+9+9 = 90 = 9 + 0 = 9
if((zeroCnt != 0) && (SingleDigitSum(sum) == 9))
{
retValue = TRUE;
}
}
}
}
}
| Is This Answer Correct ? | 2 Yes | 0 No |
What is the mean of function?
a character variable can at a time store a) 1 character b) 8 characters c) 254 characters d) none of the above
Which header file is essential for using strcmp function?
How can you determine the size of an allocated portion of memory?
What are directives in c?
what are the 10 different models of writing an addition program in C language?
what is the difference between c and c++?
What is NULL pointer?
What is volatile keyword in c?
Which sorting algorithm is the best?
How a string is stored in c?
array contains zeros and ones as elements.we need to bring zeros one side and one other side in single parse. ex:a[]={0,0,1,0,1,1,0,0} o/p={0,0,0,0,0,1,1,1}