Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

a c program i can not solve.

Status
Not open for further replies.

kinyas

New Member
hello everyone.
i have a problem but i can not solve it.

it is below:
-----
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.



Example:



Given Customer Number: 1234567

Number to be squared: 345

Square of it: 345 * 345 = 119025

Last two digits: 25

Resulting Card Number: 123456725



Write a C program that will input a 9-digit Credit Card Number, and will check whether it 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
----

we only see, if and switch and also some data types, we can use long, int, double, scanf.

can anyone help me? it is urgent!!!
i can not do this step!!
**
It gets the 3-digit number from the middle of the given Customer Number,
**
How can i get this?????????
 
You have a computer question, not an electronics question.

You've got all the information you need to do this, nothing tricky here. It appears as if you may have trouble with the concept of variables, math, and logical comparisons in which case I suggest you take a step back and actually learn the material. You're just asking someone to do your work for you which is not what we usually do here.
 
Wow...While I was glancing through that problem, I pretty much thought of the entire approach to solve that problem, and most of the C code to use. It's rather odd that computer programming is like second nature to me...maybe I'm just weird.
I could post it all here, but I'm rather tired and lazy so I dont feel like it. And you wouldnt really learn anything that way.

Look into character arrays for getting the numbers.
 
reply

ha!, ha!, ARRAYS is it!


for (i=0;i<=8;i++)
{
scanf("%d", a);
.
.
}

now say char e[2], f[1]; int mid_digits, last_digits, squared;
e[0]=a[2];
e[1]=a[3];
e[2]=a[4];

mid_digits=atoi(e);

f[0]=a[7];
f[1]=a[8];


last_digits=atoi(f);

squared=mid_digits*mid_digits;

/* now the square of a three digit number can either be 5 or 6 digits? */

if (squared < 315)
/*check if 315 is the smallest number when squared that would give you a five digit number*/

evaluate last two digits i.e z[3] and z[4] say.

if (squared > 315)

evaluate last two digits i.e squared[4] and squared[5]

compare this with a[7] and a[8], if similar then

printf("correct CARD NUMBER");

if different

printf("wrong CARD NUMBER try again :) ");

you get it?
now this might have errors in it -of course there were many non-C elements in the code- my aim was just to give you an idea. if it's wrong or has any problems let me know.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top