Skip to content

Basic Example

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
# Reference Solution from Instructor
#include<stdio.h>
int check_prime(int num){
    if(num==1){
        return 1;
    }
    int j,flag=0;
    for(j=2;j<=num/2;++j){
        if(num%j==0){
            flag=1;
            break;
        }
    }
    return flag;
}

int main(){
   int n1,n2,i,flag;
   scanf("%d %d",&n1, &n2);
   for(i=n1;i<=n2;++i){
      flag=check_prime(i);
      if(flag==0)
         printf("%d ",i);
   }
   return 0;
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Example Student Submission (Incorrect)
#include<stdio.h>
int check_prime(int num){
    int i;
    scanf("%d",&num);
    for(i=2;i<=num-1;i++){
       if(num%i==0){
           return 0;
       }  
    }
    return 1;
}

int main(){
    int i,n1,n2;
    scanf("%d %d",&n1,&n2);
    for(i=n1;i<=n2;i++)   
        if(check_prime(i)){
            printf("%d", i);   
        }
    return 0;
}

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;} in check_prime function.
  • remove scanf("%d",&num); in check_prime function.
  • change printf("%d", i); to printf("%d ", i); in the main function.

Final ITS Feedback:

  1. 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.
  2. Lack of Special Case Handling for 1: The function does not account for the fact that 1 is not a prime number.
  3. 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.