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



A MobileNumber is a VIP number if it satisfy the following conditions. The operator should be V..

Answer / c.p.senthil

// 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

Post New Answer

More C Interview Questions

write a program to add two numbers of any size.....(remember any size)

1 Answers  


.find the output of the following program? char*myfunc(char*ptr) { ptr +=3; return (ptr); } int main() { char*x,*y; x="HELLO"; y=myfunc(x); printf("y = %s ",y); return 0; }

0 Answers  


A B C D E F G F E D C B A A B C D E F F E D C B A A B C D E E D C B A A B C D D C B A A B C C B A A B B A A A

2 Answers  


What is the purpose of void pointer?

0 Answers  


What is a lookup table in c?

0 Answers  






When is a null pointer used?

0 Answers  


What are different types of operators?

0 Answers  


What is #pragma statements?

0 Answers  


why the execution starts from main function

9 Answers  


A stack can be implemented only using array?if not what is used?

3 Answers   InterGlobal,


consider the following program sigment int n,sum=1; switch(n) { case 2:sum=sum+2; case 3:sum*=2; break; default:sum=0;} if n=2, what is the value of sum a.0 b.6 c.3 d.none

7 Answers   TCS,


How can variables be characterized?

0 Answers  


Categories