Basic Example
Print Prime Number within a Range
We demonstrate the use of ITS through a few programming tasks at different difficulty levels.
We start with a typical task at the first-year programming course level (resource), which is a variant of the classic prime number problem.
Problem Statement:
Given two positive integers, n1
and n2
, output all the prime numbers between (and including) n1
and n2
, separated by a space each.
The student makes three mistakes in the code:
- The
check_prime
function unnecessarily takes an input. - Edge case handling for the number 1 is missing.
- The output format is incorrect as it does not include a space between the numbers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
Given the reference solution as expected program specification, the ITS identifies and fixes all three mistakes in the student submissions that introduce deviation from the expected behavior. The fixing patches are then provide as hint and elaborated by the GenAI-based feedback generator to produce a detailed explanation of the mistakes.
Fixing Patches from ITS Repair Engine:
- add
if(num==1){return 1;}
incheck_prime
function. - remove
scanf("%d",&num);
incheck_prime
function. - change
printf("%d", i);
toprintf("%d ", i);
in themain
function.
Final ITS Feedback:
- Misplaced Input Operation: The
check_prime
function unnecessarily takes an input. This is incorrect as the function is supposed to only check if the number passed to it is prime or not, and not to ask for any input. This causes the function to overwrite the input number num with a new user-provided value each time, defeating its purpose. - Lack of Special Case Handling for 1: The function does not account for the fact that 1 is not a prime number.
- Output Format Issue: In the main function, when printing prime numbers, the output format is incorrect as it does not include a space between the numbers.