Pelles C forum

C language => Beginner questions => Topic started by: copex on April 02, 2007, 04:16:44 PM

Title: nead help :-)
Post by: copex on April 02, 2007, 04:16:44 PM
Hi

im trying to write a program for my pda to dispaly a 4 digit code based on the input from the
user, ive got the GUI side working i just nead hepl with the maths side....

A1 = 10
A2 = 20
H = 7

Z = (A1A2 * (H++)) * 2

result neads to show the last 4 digits of Z

(i.e)-----------------------

Z = 1020 x 7
Z * 2

= 14280

result 4280
---------------------------

thank you for takeing the time to read this.....
Title: Re: nead help :-)
Post by: cane on April 02, 2007, 05:08:13 PM
result = Z % 10000
Title: Re: nead help :-)
Post by: frankie on April 03, 2007, 10:42:32 AM

int A1 = 10;
int A2 = 20;
int H = 7;
int Z;

char *sample(void)
{
    static char string[256];

    Z = (((A1*100)+A2) * (H++)) * 2
    sprintf(string,"%d", Z);
    return (string + (strlen(string) - 4));
}
Title: Re: nead help :-)
Post by: copex on April 03, 2007, 06:32:23 PM
Thank you,

for the help, most intresting, ill give it a try