COMP 235, Fall 2022, Program 1

Intro to C

Due Monday, September 5 by the start of class.

You will need to do this assignment on the department server ( Start early so you can comfortable in that environment.

Part 1: Exponentiation

Starting from this template, complete the power function. It takes in a base (a double), an exponent called exp (an int), and should return base raised to the exp power. In other words, baseexp.

The main function allows the user to enter inputs and perform the exponentiation operation. If you would like to write tests for your code (recommended), place it near the TESTING HERE block at the start of main(). Do not modify below that point.

For testing, you might try running man assert on the command line, or try searching for “assert.h” online.

Part 2: FooBar

Start from this template. First, complete the foobar function. Given an input integer n, foobar should loop from 1 to n (inclusive). For each number, foobar will print a value on a separate line. If the number is divisible by 4, it should print “Foo”. If the number is divislbe by 6, it should print “Bar”. If the number is divisible by 4 AND 6, it should print “FooBar”. Otherwise, it should print the number itself.

For example, calling foobar(7) should print


Your main function should first check the number of arguments. The program itself should take exactly one argument, e.g., ./a.out 7. With any other number of arguments, the program should print an error message and immediately stop, returning 1.

When given a single argument, you should convert the argument into an integer, call foobar with it, and return 0. You do not need to do any error checking on the argument itself – you may assume it is an integer.


We will submit using the handin program. Assuming you have not renamed the files, you can run

handin comp235 proj1 expt.c foobar.c

to submit your solutions. You can run this command multiple times in case you discover an error after submitting.