Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/07/04 06:46
Read: times


 
Msg Score: +1
 +1 Good Question
#71947 - Weekend Puzzle
Here I have a little C-51 program that I wrote as a puzzle using the Keil tools. I thought to post this because there have been a number of requests recently regarding learning C coding. What better way to sharpen C skills than to study some code. When you set out to evaluate this feel free to select a 3-digit decimal (base 10) number to assign to the you_pick variable. I would ask some questions about the program:

- First...What does this code actually produce?

- Second..What happens with different you_pick values.

- Third...Are all values for you_pick doing what you expect?

- Fourth...Why does this produce the behavior that it does?


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

unsigned int you_pick=123;              // select a 3 digit number

void main(void)
{
    int a=321, b, c;
    unsigned char str[11];
    unsigned char z;

    sprintf(str,"%03i %03i", b=you_pick, a);
    str[8]  =  str[4];
    str[4]  =  str[0];
    str[9]  =  str[5];
    str[5]  =  str[2];
    str[10] =  str[6];
    str[0]  =  str[2];
    str[5] -=  str[0];
    str[2]  =  str[4];
    str[3]  =  str[5];
    a = atoi(str);

    z = a > b;

    b = (z * a + !z * b) - (z * b + !z * a);

    sprintf(str, "%03i%03i", a=b, b);
    
    str[0]  = str[5];
    str[11] = str[6];
    str[2]  = str[3];
    str[3] -= str[2];
    str[7]  = str[9];

    sscanf(str,"%03i", &c);

    a = b + c + atoi(str+7)*3;

    sprintf(str,"%04d.com", a);

    while(1);
}


Have Fun !!
Michael Karas


List of 35 messages in thread
TopicAuthorDate
Weekend Puzzle            01/01/70 00:00      
   RE: Weekend Puzzle            01/01/70 00:00      
   RE: Weekend Puzzle            01/01/70 00:00      
      RE: Weekend Puzzle            01/01/70 00:00      
      RE: Weekend Puzzle            01/01/70 00:00      
         RE: Weekend Puzzle            01/01/70 00:00      
         RE: Weekend Puzzle            01/01/70 00:00      
            RE: Weekend Puzzle            01/01/70 00:00      
               RE: Weekend Puzzle            01/01/70 00:00      
   RE: Weekend Puzzle            01/01/70 00:00      
      RE: Weekend Puzzle            01/01/70 00:00      
         RE: Weekend Puzzle            01/01/70 00:00      
            RE: Weekend Puzzle            01/01/70 00:00      
               RE: Weekend Puzzle            01/01/70 00:00      
            RE: Weekend Puzzle            01/01/70 00:00      
               RE: Weekend Puzzle            01/01/70 00:00      
            RE: Weekend Puzzle            01/01/70 00:00      
               RE: Weekend Puzzle            01/01/70 00:00      
                  RE: Weekend Puzzle            01/01/70 00:00      
                     RE: Weekend Puzzle            01/01/70 00:00      
                  RE: Weekend Puzzle            01/01/70 00:00      
                     RE: Weekend Puzzle            01/01/70 00:00      
   Understanding logic expressions !!!            01/01/70 00:00      
      RE: Understanding logic expressions !!!            01/01/70 00:00      
   RE: Weekend Puzzle            01/01/70 00:00      
      RE: Weekend Puzzle            01/01/70 00:00      
         RE: Weekend Puzzle            01/01/70 00:00      
   RE: Weekend Puzzle            01/01/70 00:00      
   My Conclusion            01/01/70 00:00      
      RE: My Conclusion            01/01/70 00:00      
   Whats the trick, Michael ?            01/01/70 00:00      
      RE: Whats the trick, Michael ?            01/01/70 00:00      
         RE: Whats the trick, Michael ?            01/01/70 00:00      
            RE: Whats the trick, Michael ?            01/01/70 00:00      
               RE: Whats the trick, Michael ?            01/01/70 00:00      

Back to Subject List