| ??? 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 |



