Click on any exercise below to see the source code, program output and explanation of the code.  Programs under this section make use of arithmetic operators and printf function to display information to the stdout.

Available Exercises

Exercise 1.1. Input two numbers and work out their sum, average and sum of the squares of the numbers.

Exercise 1.2. Given as input a floating (real) number of centimeters, print out the equivalent number of feet (integer) and inches (floating, 1 decimal), with the inches given to an accuracy of one decimal place.

   Assume 2.54 centimeters per inch, and 12 inches per foot.
   If the input value is 333.3, the output format should be:
   333.3 centimeters is 10 feet 11.2 inches.

Exercise 1.3. Write a program to output an integer in decimal format and a floating point number in float format. Experiment with outputting an integer in float format and visa versa. Output a character in decimal format (prints the character code e.g. ascii). Fix any problems by using an explicit type coercion or cast.

Exercise 1.4. Write a C program that convert an amount in dollar to an amount in FCFA.

Exercise 1.5. Write a C program that calculates the voltage of the circuit below.

Exercise 1.5 Circuit

Take R1 = 2Ω, R2 = 4Ω, R3 = 10Ω, I = 20A

Exercise 1.6. Write a C program that computes the volume of a sphere.

Exercise 1.7. Write a C program that computes the volume of a pendulum.

Exercise 1.8. Write a C program that computes the area of a trapezium.

Exercise 1.9. Given the circuit diagram below, write a C program that calculates the following:

  1. The potential difference across x
  2. The charge on z
  3. The energy on y

Exercise 1.9 Circuit

Exercise 1.10. Write, compile and run a program that displays your Name, Surname, Date of Birth, Place of Birth, Phone Numbers, Websites, Job Title, and Marital Status.

Exercise 1.11. Write, compile and run a program that displays the following lines:
O Cameroon thou cradle of our fathers
...
Thy welfare we will win in toil and love and peace

Exercise 1.12. What are the errors in the following programs:
(a)

main(){printf "Once upon a time,"; print "Ten times"}


(b)

#include <math.h>
main(){
printf(Enter an integer number:);
scanf("%d",&X);
printf("X to the forth power is:%d",pow(X,4));
}

Exercise 1.13. What does the program below do?

#include<stdio.h>
main(){
    float largest, number;
    largest = 0;
    printf("\nEnter a number (0 to end): ");
    scanf("%f",&number);
    while(number != 0){
        if(number > largest) largest = number;
        printf("\nEnter a number (0 to end): ");
        scanf("%f",&number);
    }
    printf("\nThe largest is %6.2f\n",largest);
}