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.

Odd-Even Ten

Write a C program odd_even_ten.c which reads 10 integers from standard input, prints the odd numbers on one line, then prints the even numbers on one line.

You may assume that the program's input will contain only positive integers and will contain at least 10 integers, in other words you can assume scanf succeeds.

Match the the example below EXACTLY.

dcc odd_even_ten.c -o odd_even_ten
./odd_even_ten
3
4
5
6
7
9
8
7
6
5

Odd numbers were: 3 5 7 9 7 5
Even numbers were: 4 6 8 6
./odd_even_ten
1
2
4
16
32
64
128
256
512
1024
Odd numbers were: 1
Even numbers were: 2 4 16 32 64 128 256 512 1024
./odd_even_ten
3
5
7
11
13
11
9
7
5
3
Odd numbers were: 3 5 7 11 13 11 9 7 5 3
Even numbers were:

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

1511 autotest odd_even_ten

Autotest Results

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

Odd-Even Negative

Write a C program odd_even_negative.c which reads integers from standard input until it reads a negative integer. It should then print the odd numbers on one line then print the even numbers on one line.

You may assume that the program's input will contain only integers, in other words you can assume scanf succeeds.

You can assume a negative integer will always be read.

You can assume at most 1000 integers are read before a negative integer is read.

Match the the example below EXACTLY.

./odd_even_negative
1
2
3
2
-42
Odd numbers were: 1 3
Even numbers were: 2 2
./odd_even_negative
1
2
4
16
32
64
128
256
512
1024
2048
4096
-8192
Odd numbers were: 1
Even numbers were: 2 4 16 32 64 128 256 512 1024 2048 4096
Hint: use odd_even_ten.c as a starting point.

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

1511 autotest odd_even_negative

Autotest Results

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

Indivisible Numbers

Write a C program indivisible.c which reads integers > 1 from standard input until it reaches end-of-input.

It should then print the integers read which are not exactly divisible by any other of the integers read.

In other words it should not print an integer if another integer that has been read is a factor of that number.

You may assume that the program's input will contain only positive integers one per line.

You may assume that all integers are > 1.

You can assume at most 1000 integers will be read before end-of-input is reached.

Match the the example below EXACTLY.

./indivisible
42
7
6
12

Indivisible numbers: 7 6
./indivisible
2
3
4
5
6
7
8
9
10

Indivisible numbers: 2 3 5 7
./indivisible
5
6
5

Indivisible numbers: 6
./indivisible
4
7
4

Indivisible numbers: 7

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

1511 autotest indivisible

Autotest Results

84% of 767 students who have autotested indivisible.c so far, passed all autotest tests.
  • 86% passed test 0
  • 86% passed test 1
  • 85% passed test 2
  • 85% passed test 3
  • 85% passed test 4
When you are finished working on this exercise you must submit your work by running give:
give cs1511 test06_indivisible indivisible.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 Wednesday 18 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