Question:
A Credit Card company uses a method to generate its own
valid Card Numbers. Given 7-digit Customer Number, a Card Number is generated,
consisting of 9 digits. The Method is as follows:
It gets the 3-digit number from the middle of the given Customer
number,
It takes the square of this 3-digit number
It adds one to this square if the first digit of the
customer number is EVEN.
It appends the last two digits of the result to the end of the Customer Number.
For Example:
Given Customer
Number : 1234567
Number to be
squared : 345
Square of it :
345 * 345 = 119025
Last 2 digits :
25
Resulting Card
Number : 123456725
Write a C program that will input a 9-digit Credit Card Number, and will check whether iit is valid or not (i.e. to examine if the last 2 digits of the Credit Card Number can be generated from the first 7-digit number)
Hint : use 'long' data type. Placeholder in printf or scanf is %ld for long data
To solve this problem:
1. input a
9-digit number (credit card number)
2. store the
first 7 digit number to a variable, say cust; and last two digit to another
variable, say last2.
3. find the
middle 3 digit number of cust and take square of it.
4. If the first
digit of cust is even, add one to this square. (for finding if it is even use
%2 operation to the first digit. I hope you know how to find first digit !...)
5. compare the
result with the value last2 (found on step 2) and display the corresponding
message if it is valid or not...