Hey,
So I found an interesting problem which while being simple enough, needs to use some good thinking and features of your language (at least in my opinion). The program reads:
Write a program that accepts a base ten (non-fractional) number at the command line and outputs the binary representation of that number. Sample input is
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
if(argc < 2)
{
printf("Please run the program like this: program_name decimal_number\n");
return 1;
}
int number = atoi(argv[1]);
int rem = 0;
int * binary = malloc(sizeof(int)*100);
int index = 0;
int i;
do
{
rem = number%2;
number = number/2;
binary[index] = rem;
index++;
} while(number != 0);
for(i = index-1; i >= 0; i--)
{
printf("%d", binary[i]);
}
free(binary);
return 0;
}