C Programming Problems
The First 100
(currently up to 74)
gcc –ansi -Wall
A Varied Collection of Problems for Beginning Students
Version 1.0
Last Updated – January 3, 2008
Problem 1: Hello World
Write a C program that prints out the message Hello World.
Problem 2: The Value 6
Write a C program that prints out the value 6. I want you to use the %d format code.
Problem 3: The Character P
Write a C program that prints out the single character P. I want you to use the %c format code.
Problem 4: The scanf Function
Write a C program that reads in an integer value from the keyboard via the scanf function and then prints it back onto the screen. By now you should know that scanf seeks an address expression. For example, &n is an address expression.
Problem 5: Sum of Two Values
Write a C program that reads two integer values from the keyboard via the scanf function, then adds them together, stores the result into a variable called sum, and then prints out the value of the variable sum.
Problem 6: The fscanf Function
Create file called testdata6 that has a single integer value stored into it.
Write a C program that opens a file named testdata6, reads the single value stored in it using the fscanf function, and then prints the value back onto the screen. You should call the function fclose before you return to the Unix operating system.
Problem 7: Bigger than 100?
Write a C program that reads a number from the keyboard via the scanf function, and then prints the message The number is bigger than 100 if it is. If the number is 100 or less than 100 then you should print out the message The number is not bigger than 100.
Problem 8: One Line of Asterisks
Create a file called testdata8 that has a single integer value stored into it. The integer will be a number between 1 and 30 inclusive. Create a C program that uses the fscanf function to read in this integer value and then prints a line containing