tags:

views:

353

answers:

4

I'm running out of ideas for my "Beginning C" class, and the only topics I've discussed so far are Data types, Variables & the printf & scanf functions.

My last quizzes involved simple formulas (area of a circle, volume of a cube..) enclosed inside the printfs..

eg. printf("volume = %d",length * width * height);

I'm looking for something more interesting using only printfs and scanfs :(

Update~ Just to clarify: My students don't know how to use conditional statements and iterative statements yet. It's only week 2, and this is their very first programming class :'( And yes, they can only retrieve the input, then modify it in some way before they output it in the console. I can play with escape sequences (create a box asterisks) or format specifiers (a 3 precision division operation) but that's it..

A: 

How about a base-converter. In other words, prompt for a number in decimal and a number system (say, 2 for binary or 16 for hex) and then output the number in that system.

Alex
Can you do this without a conditional like 'if (base == 16) { format = "%x"; }' ?
Paul Stephenson
I posted this before the update, I was thinking that conditionals would be allowed.
Alex
A: 

Using only printfs and scanfs, and nothing more? You can only retrieve input and output the input if that's the case.

I don't think that's what you meant though...

Math/Algorithm Related

  • Generate/Output the first N prime numbers
  • Calculate factorial(n) recursively/iteratively
  • Use C as a tool to Find a formula for sum of alternating sums up to positive N

Game Related

  • Write a simple character based pong game (single player)
  • Write "nibbles" a.k.a "snake" (char based)
Sev
You will need conditional and loop statements for most of these. First time programming students will not know how to solve these type of problems.
Gerhard
+1  A: 
  • Write a program that asks the user their name, age, and favorite letter of the alphabet.
  • Print a single sentence containing all the information.
  • Bonus: Print a sentence containing the first letter of their name.

Answer:

char name[50];
int age;
char letter;

printf( "\nWhat is your name? " );
scanf( "%s", name );

printf( "\nHow old are you? " );
scanf( "%d", &age );

printf( "\nWhat is your favorite letter of the alphabet? " );
scanf( " %c", &letter ); //skipping whitespace

printf( "\n\n-------------------\n\n");
printf( "Your name is %s, you are %d years old, and your favorite letter of the alphabet is %c.\n", name, age, letter );

printf( "The first letter of your name is %c", name[0] );

If you'd like some math in there, ask them questions like:

  • Write a program that asks the user how many weeks until christmas, then print out how many seconds there are until christmas (given the number of weeks entered only).
Curtis Tasker
+2  A: 

I have used a unit converter previously.

  • Convert temperatures to and from Celsius, Fahrenheit, and Kelvin.
  • Change the base as mentioned by Alex.
  • Cooking weights and measures has lots of interesting conversions.
Gerhard