COMP1511 18s1 (webcms)
COMP1511 18s1 (flask)

Test Conditions

These questions must be completed under self-administered exam-like conditions.

You must time the test yourself and ensure you comply with the conditions below.


You may access this language documentation while attempting this test:
Any violation of the test conditions will results in a mark of zero for the entire weekly test component.

Counting Up

Write a C program count_up.c that reads 2 positive integers and prints the integers between them, one per line.

Your program should behave exactly like these examples:

dcc count_up.c -o count_up
./count_up
Enter lower: 4
Enter upper: 8
5
6
7
./count_up
Enter lower: 9
Enter upper: 15
10
11
12
13
14
./count_up
Enter lower: 42
Enter upper: 43

You can assume the user supplies 2 positive integers.

You can assume the first integer is smaller than the second.

You do not have do any error checking.

You do not have to check the return value from scanf.

When you think your program is working you can autotest to run some simple automated tests:

1511 autotest count_up

Autotest Results

99% of 921 students who have autotested count_up.c so far, passed all autotest tests.
  • 99% passed test 0
  • 99% passed test 1
  • 99% passed test 2
  • 99% passed test 3
  • 99% passed test 4
When you are finished working on this exercise you must submit your work by running give:
give cs1511 test05_count_up count_up.c

An Odd Product

Write a C program product_odd.c that reads 2 positive integers and calculates the product of the odd integers between the first and second integers.

For example, if the two integers entered are 10 and 16 then 2145 should be printed because 11 * 13 * 15 = 2145.

If there are no odd integers between the first and second integers, your program should print 1.

Your program should behave exactly like these examples:

dcc product_odd.c -o product_odd
./product_odd 
Enter lower: 10
Enter upper: 16
2145
./product_odd 
Enter lower: 4
Enter upper: 8
35
./product_odd 
Enter lower: 5
Enter upper: 7
1
./product_odd 
Enter lower: 5
Enter upper: 9
7

You can assume the user supplies 2 positive integers.

You can assume the first integer is smaller than the second.

You can assume that the product will fit in an ''int''. In other words you can assume overflow does not occur.

You do not have do any error checking.

You do not have to check the return value from scanf.

When you think your program is working you can autotest to run some simple automated tests:

1511 autotest product_odd

Autotest Results

97% of 910 students who have autotested product_odd.c so far, passed all autotest tests.
  • 98% passed test 0
  • 98% passed test 1
  • 98% passed test 2
  • 98% passed test 3
  • 98% passed test 4
  • 98% passed test 5
  • 98% passed test 6
  • 98% passed test 7
When you are finished working on this exercise you must submit your work by running give:
give cs1511 test05_product_odd product_odd.c

It's Prime

Write a program called prime_factors.c that reads a integer n from standard input and prints the decomposition of n into prime factors.

If n is prime it should instead print "n is prime" (where n is the integer).

Make your program match the examples below exactly.

./prime_factors
Enter number: 6
The prime factorization of 6 is:
2 * 3 = 6
./prime_factors
Enter number: 30
The prime factorization of 30 is:
2 * 3 * 5 = 30
./prime_factors
Enter number: 127
127 is prime
./prime_factors
Enter number: 2048
The prime factorization of 2048 is:
2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 = 2048
./prime_factors
Enter number: 22500
The prime factorization of 22500 is:
2 * 2 * 3 * 3 * 5 * 5 * 5 * 5 = 22500
./prime_factors
Enter number: 22501
22501 is prime

You can assume the user supplies an integer n > 2.

You do not have do any error checking

You do not have to check the return value from scanf.

When you think your program is working you can autotest to run some simple automated tests:

1511 autotest prime_factors

Autotest Results

87% of 797 students who have autotested prime_factors.c so far, passed all autotest tests.
  • 92% passed test 0
  • 93% passed test 1
  • 92% passed test 2
  • 92% passed test 3
  • 93% passed test 4
  • 93% passed test 5
  • 91% passed test 6
  • 91% passed test 7
When you are finished working on this exercise you must submit your work by running give:
give cs1511 test05_prime_factors prime_factors.c

Submission

When you are finished each exercise make sure you submit your work by running give.

You can run give multiple times. Only your last submission will be marked.

Don't submit any exercises you haven't attempted.

If you are working at home, you may find it more convenient to upload your work via give's web interface.

Remember you have until Thursday 12 April 23:59:59 to complete this test.

Automarking will be run several days after the submission deadline for the test. When complete you can view automarking here and you can view the the resulting mark via give's web interface