Programming Activity 1

Go through the lecture slides and any other material you might have at your disposal and complete the following programming assignment.

Create in your ~/csci315 directory, create a sub-directory called Activities, in which you will create a file called activity1.c. At the start of this file, write a comment with your name and the name of a partner who will work with you in this class period.

By the end of the class period, make sure to have added, committed, and pushed this file to your git repository. (Be nice and email it to your partner, as well.)

In file activity1.c you will write a program that does the following:

  • Receives a integer number N as a command line parameter.
  • Contains a function called summation that receives two integer arguments i and j, calculates the sum of the integers from i to j-1 and returns the result to the caller.
  • In your main program, use your summation function to create two threads to compute the summation of integers: from 1 to (N/2 – 1) and from (N/2 -1) to N. Of course, N is the number you received through the command line. •
  • When each thread terminates, it passes the result of its computation back to the main function, which adds the two results and prints it out to the standard terminal.
Print Friendly