1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

A general problem

Discussion in 'C' started by macchiato, Mar 26, 2008.

  1. macchiato

    macchiato New Member

    Joined:
    Mar 23, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Hi guys. . I'm a newbie /maybe dummy :)/
    teacher gave me homework.. but I can"n solve it.. Can sum1 help me??

    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)


    I've started this thread appealing to lead.smart34's advice.. All "responsibilities" belongs to her/him.. :)

    Now let present my sollution.
    algortihm :
    1- enter 9 digited numbers
    2- get 3rd 4 and 5th digits and create a 3 digited number. say this number x
    3- find square of x
    4- get 8 and 9 th digits and say this 2 digited number y
    5- compare x and y in (mod10)
    6.a- if they're equal in mod10 print "valid credti card number"
    6.b- else "invalid credit card number"



    Firstly I defined the a1, a2 ... a9 variables.
    Then wrote the printf("Enter 9 digited c.c. numba" );
    then, scanf all a1 a2 ... a9

    I dont know how to get a3a4a5 and a8a9 as a number.

    I can do the end.. Such let's say x to the square of a3a4a5.. and y to a8a9 /two digited number/
    Then we can compare .

    if(x %10== y)
    {
    printf("valid c.c. number");
    }
    else
    {
    printf("invalid c.c. number");
    }

    I hope I could describe the problem..
     
  2. sumeetsenapati

    sumeetsenapati New Member

    Joined:
    Mar 7, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    helo macchiato,
    I ll giv u a code which i think can b useful 2 convert frm individual digits 2 a no.supose u hav 3 diferent no.a[3],a[4],a[5].u can combin dem by s=100*a[3]+10*a[4]+a[5] similarly p=10*a[8]+a[9]
     
  3. sumeetsenapati

    sumeetsenapati New Member

    Joined:
    Mar 7, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    helo macchiato,
    I ll giv u a code which i think can b useful 2 convert frm individual digits 2 a no.supose u hav 3 diferent no.a[3],a[4],a[5].u can combin dem by s=100*a[3]+10*a[4]+a[5] similarly p=10*a[8]+a[9].i hope u ca do d rest
     

Share This Page