Spring2011.CSCI340Homework2 History

Show minor edits - Show changes to markup

Changed lines 142-143 from:

% submit csci340 hmwk2 maxMinInt.c pythagorean.c evenSum.c diamond.c hypotenuse.c prime.c reverse.c

to:

% submit csci340 hmwk2 maxMinInt.c pythagorean.c evenSum.c diamond.c hypotenuse.c prime.c reverse.c

Changed lines 142-145 from:

% submit csci340 hmwk2 files

where files are the names of your source files (e.g, maxMinInt.c, pythagorean.c, etc.), as described above.

to:

% submit csci340 hmwk2 maxMinInt.c pythagorean.c evenSum.c diamond.c hypotenuse.c prime.c reverse.c

Changed lines 89-90 from:

Your programs should perform thorough error checking.

to:

Your programs should perform reasonably thorough error checking.

Changed line 2 from:

Due Date: Friday, Feb. 18, 2011\\

to:

Due Date: Monday, Feb. 21, 2011\\

Changed lines 61-62 from:

Use the following format precisely (user input in italics):

to:

Use the following format precisely (user input in italics):

Added line 70:
Added line 80:
Changed lines 37-38 from:

A few more problems to be added soon...

to:

evenSum.c - Write a program that calculates and prints the sum of all even integers from 2 to X (inclusive), where 'X' is an integer value provided as input. It should keep looping until the user enters 0.

Use the following format precisely (user input in italics):

Enter your max number: 6
The sum of all even numbers from 2 to 6 is 12
Enter your max number: 2
The sum of all even numbers from 2 to 2 is 2
Enter your max number: 0

diamond.c - Write a program that outputs the following shape. You may use printf statements that print either a single asterisk or a blank. Maximize use of nested for loops and minimize use of printf statements. Define a constant, MAX_WIDTH, to make your code easy to maintain - i.e., for the following output, use #define MAX_WIDTH 9.

     *
    ***
   *****
  *******
 *********
  *******
   *****
    ***
     * 

hypotenuse.c - Define a function, called hypotenuse(), which calculates the length of the hypotenuse of a right triangle when the other two sides are given as arguments to the function. Then, use this function in a program that accepts 2 integers as input and outputs the length of the hypotenuse. It should keep looping until the user enters two zero integers.

Use the following format precisely (user input in italics):

Enter two triangle sides: 3 4
The hypotenuse of the right triangle with sides 3 and 4 is: 5
Enter two triangle sides: 0 0

prime.c - An integer is said to be prime if it's divisible only by 1 and itself. For example, 2, 3, 5 and 7 are prime, but 4, 6, 8 and 9 are not. Write a function, called isPrime(), which takes a single integer as argument and determines if it is a prime number (should return either 0 or 1). Then, use this function in a program that takes a single integer as input and outputs if the number is prime. It should keep looping until the user enters a zero integer.

Use the following format precisely (user input in italics):

Enter a single integer: 6
The number 6 is not prime.
Enter a single integer: 11
The number 11 is prime.
Enter a single integer: 0

reverse.c - Write a function that takes a single integer as argument and returns the number with all its digits reversed. Then, use this function in a program that takes a single integer as input and outputs the reverse of the value given. It should keep looping until the user enters zero.

Use the following format precisely (user input in italics):

Enter a number: 1234
The reverse of 1234 is 4321
Enter a number: 8374
The reverse of 8374 is 4738
Enter a number: 0
Changed lines 94-97 from:

% submit csci340 hmwk2

where are the names of your source files (e.g, maxMinInt.c, pythagorean.c, etc.), as described above.

to:

% submit csci340 hmwk2 files

where files are the names of your source files (e.g, maxMinInt.c, pythagorean.c, etc.), as described above.

Changed lines 37-38 from:

...

to:

A few more problems to be added soon...

Changed lines 1-2 from:

Assigned Date: Monday, Jan. 24, 2011
Due Date: Wednesday, Feb. 2, 2011\\

to:

Assigned Date: Friday, Feb. 11, 2011
Due Date: Friday, Feb. 18, 2011\\

Changed lines 20-21 from:
to:

maxMinInt.c - Write a program that reads in five integers and then determines and prints the largest and the smallest.

Use the following format precisely (user input in italics):

Enter five integers: 3 4 1003 -3 3
The smallest is -3 and the largest is 1003.

pythagorean.c - Write a program that reads in three nonzero integers and determines if they correspond to sides of a right triangle. It keeps looping until the user enters three zero integers.

Use the following format precisely (user input in italics):

Enter three integers: 3 4 5
Integers 3, 4, and 5 are Pythagorean triples.
Enter three integers: 1 2 3
Integers 1, 2, and 3 are not Pythagorean triples.
Enter three integers: 0 0 0

...

Details

Your programs should perform thorough error checking.

Changed lines 94-97 from:

% submit csci340 hmwk2 hmwk2.c

where hmwk2.c is the name of your source file, as described above.

to:

% submit csci340 hmwk2

where are the names of your source files (e.g, maxMinInt.c, pythagorean.c, etc.), as described above.

(NOTE: Make sure you submit all your files with a single submit command. Otherwise, the latest submitted files will overwrite any previous ones - even if they have different names!)

Changed lines 110-112 from:
  1. Cooper, D. and Clancy, M. (1985) "Oh! Pascal", 2nd ed., W.W. Norton & Company, New York, p. 42.
to:
  1. Cooper, D. and Clancy, M. (1985) "Oh! Pascal", 2nd ed., W.W. Norton & Company, New York, p. 42.

(This assignment was adapted from Deitel & Deitel, "C - How to Program".)

Added lines 1-87: