Working with C

Tasks

Task 1. Write a pure C program that calculates the product of two integers given as command line arguments. Look out for overflow, assume that the product fits into unsigned long long. Test your program using the debugger in an IDE of your choice.

This will be very contrived, but create your program in two source files. One should contain the main function and the input and output routines, the other should contain the function that calculates the product. Create a suitable Makefile.

GCC supplies the __int128 type that can store integers up to 128 bits (twice longer then long long). Unfortunately there is no easy way to read and write such numbers. But they can be used in calculations to prevent overflow.

Task 2. Write a C++ program that calculates the product of two integers given as command line arguments. Look out for overflow, assume that the product fits into unsigned long long. Test your program using the debugger in an IDE of your choice.

Task 3. Write a C program that calculates the product of two integers given as command line arguments. Do not assume that the product fits into unsigned long long. Test the program in an IDE.

Task 4. Write a C++ program that calculates the product of two integers given as command line arguments. Do not assume that the product fits into unsigned long long.

All the solutions can be downloaded here.