CSE 1311 - Section 2 - Assignments - Assignment 3

Due date: Wednesday, February 17, 2010, 11:55pm.


Task 1 (25 points)

Write a program, in a file called task1.c, that does the following:

Your solution must satisfy the following requirements:


Task 2 (25 points)

Mr. Bugs wants to write a simple program that sums up 1/4 + 1/5 + 1/6 + 1/7 + 1/8 + 1/9 + 1/10. Unfortunately, the computer prints out that "the sum is 0.000000". Can you help Mr. Bugs fix his code?

Submit a file called task2.c, with the corrected version of the code. Here is the program that Mr. Bugs wrote:

#include <stdio.h>

int main()
{
  int i;
  double result = 0;
  for (i = 4; i <= 10; i++)
  {
    result = result + 1/i;
  }
  
  printf("the sum is %lf\n", result);
}


Task 3 (25 points)

Write a program, in a file called task3.c, that does the following:

Your program should work with any integer values A and B. Here are some examples: Important: here is code you can use to store integer values in double numbers:
int a, b;
double a2, b2;
printf("enter A and B:\n");
scanf("%d %d", &a, &b);
a2 = a;
b2 = b;
You may (or may not) need to do that, depending on your solution. Have in mind that, in the C language, 1/4 is equal to 0, if 1 and 4 are integers, but 1.0/4.0 is equal to 0.25., if 1.0 and 4.0 are doubles.


Task 4 (25 points)

Write a program, in a file called task4.c, that redoes task 3, but using a function. In particular, you should define a function called double sum_fractions(int A, int B) that, assuming that A <= B, A returns the sum 1.0/A + 1.0/(A+1) + 1.0/(A+2) + ... + 1.0/B. Important: as in task 2, you may find it useful to convert A and B into doubles inside your function, with code such as:
double sum_fractions(int A, int B)
{
  double A2, B2;
  ...
  A2 = A;
  B2 = B;
}


How to submit

Submisions are only accepted via WebCT. The submission should include files task1.c, task2.c, task3.c, task4.c, answers.doc. Do not submit entire project directories, or anything else except for the .c files and the answers.doc file.

Your answers.doc file should be a single Microsoft Word file that includes:

Make sure that your answers.doc file is easy to parse, and that it is easy for us to figure out which part corresponds to which task. Feel free to use headings such as "start of copy of task1.c".

We try to automate the grading process as much as possible. Not complying precisely with instructions causes a significant waste of time during grading, and thus points will be taken off for failure to comply, and/or you may receive a request to resubmit.

Submission checklist