CodeGraderBench/CodeGraderBench huggingface dataset:
Problem: Write a C++ program to find all prime numbers from 2 to n (n taken as input from the user) following the procedure given below:Create an array of consecutive integers from 2 through n: (2, 3, 4, ..., n).Initially, let p equal 2, the smallest prime number. Enumerate the multiples of p by counting in increments of p from 2p to n, and mark them in the array as non-prime (these will be 2p, 3p, 4p, ...; the p itself should not be marked). Find the smallest number in the array greater than p that is not marked. If there was no such number, stop. Otherwise, let p now be equal to this new number (which will be the next prime number), and repeat from step 3.When the algorithm terminates, the numbers remaining not marked in the array are all the primes below n. Your program should print out all prime numbers from 2 to n. You do not need to use functions in this task (you may if you wish to). 

Input Format - Integer n.
Output Format - Print out the prime numbers with a space in between. After every five prime numbers print a newline character for ease of reading. 

Constraints
n >= 2 and n <= 500

Student submission:
#include<iostream>
using namespace std;

int main()
{
int n,j=0;

cin>>n;

int a[n-1];


for(int i=0;i<n-1;i++)
{
a[i]=i+2;
}

for(int d=0;d<n-1;d++)
{
 for(int i=0;i<n-1;i++)
 {
  for(int b=2;b<=n;b++)
  {
   if(a[i]==b*a[d])a[i]=0;
  }
 }
}

for(int i=0;i<n-1;i++)
{
 if(a[i]!=0)
 {
  
  if(j==5)
  {
   printf("\n");
   j=1;
  }
  else j=j+1;
  cout <<a[i]<<" ";
 }
}
return 1;
}

Grading criterion: Variable Names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor variable names
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to find all prime numbers from 2 to n (n taken as input from the user) following the procedure given below:Create an array of consecutive integers from 2 through n: (2, 3, 4, ..., n).Initially, let p equal 2, the smallest prime number. Enumerate the multiples of p by counting in increments of p from 2p to n, and mark them in the array as non-prime (these will be 2p, 3p, 4p, ...; the p itself should not be marked). Find the smallest number in the array greater than p that is not marked. If there was no such number, stop. Otherwise, let p now be equal to this new number (which will be the next prime number), and repeat from step 3.When the algorithm terminates, the numbers remaining not marked in the array are all the primes below n. Your program should print out all prime numbers from 2 to n. You do not need to use functions in this task (you may if you wish to). 

Input Format - Integer n.
Output Format - Print out the prime numbers with a space in between. After every five prime numbers print a newline character for ease of reading. 

Constraints
n >= 2 and n <= 500

Student submission:
#include<iostream>
using namespace std;
int main(){
int n;
cin >> n;
int a[n-1];
a[0]=2;
int b[n-1];
b[0]=2;
int p=2;
while(p>0){
for(int i=1;i<n-1;i++){a[i]=a[i-1]+1;}
for(int i=1;i<n-1;i++){
if(a[i]%p!=0)
{ b[i]=a[i];}
else b[i]=0; } 
for(int i=1;i<n-1;i++)
if(b[i]>p){ p=b[i];break;}
 }for(int i=1;i<n-1;i++){
if(b[i]!=0) cout << b[i] << " ";}
}

Grading criterion: Variable Names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor variable names
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to find all prime numbers from 2 to n (n taken as input from the user) following the procedure given below:Create an array of consecutive integers from 2 through n: (2, 3, 4, ..., n).Initially, let p equal 2, the smallest prime number. Enumerate the multiples of p by counting in increments of p from 2p to n, and mark them in the array as non-prime (these will be 2p, 3p, 4p, ...; the p itself should not be marked). Find the smallest number in the array greater than p that is not marked. If there was no such number, stop. Otherwise, let p now be equal to this new number (which will be the next prime number), and repeat from step 3.When the algorithm terminates, the numbers remaining not marked in the array are all the primes below n. Your program should print out all prime numbers from 2 to n. You do not need to use functions in this task (you may if you wish to). 

Input Format - Integer n.
Output Format - Print out the prime numbers with a space in between. After every five prime numbers print a newline character for ease of reading. 

Constraints
n >= 2 and n <= 500

Student submission:
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
int a[n-1];
for(int i=0;i<n-1;i++){
a[i]=i+2;
}
int p=2;
for(int j=p-1;j<n-1;j++){
for(int i=p-1,t=2;i<n-1;i++){
if(a[i]==t*p)
{a[i]=0;}
if(a[i]>t*p){t++;}
}
if(a[j]!=0){p=a[j];}
}
int k=0;
for(int i=0;i<n-1;i++){
if(a[i]!=0){cout<<a[i]<<" ";k++;
}
if(k%5==0&&k!=0){cout<<endl;k=0;}
}

}

Grading criterion: Variable Names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor variable names
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to find all prime numbers from 2 to n (n taken as input from the user) following the procedure given below:Create an array of consecutive integers from 2 through n: (2, 3, 4, ..., n).Initially, let p equal 2, the smallest prime number. Enumerate the multiples of p by counting in increments of p from 2p to n, and mark them in the array as non-prime (these will be 2p, 3p, 4p, ...; the p itself should not be marked). Find the smallest number in the array greater than p that is not marked. If there was no such number, stop. Otherwise, let p now be equal to this new number (which will be the next prime number), and repeat from step 3.When the algorithm terminates, the numbers remaining not marked in the array are all the primes below n. Your program should print out all prime numbers from 2 to n. You do not need to use functions in this task (you may if you wish to). 

Input Format - Integer n.
Output Format - Print out the prime numbers with a space in between. After every five prime numbers print a newline character for ease of reading. 

Constraints
n >= 2 and n <= 500

Student submission:
#include<iostream>
using namespace std;

int main(){
	int n;cin>>n;
	if(n==2) cout<<2;return 0 ;
	int arr[n-1];
	for(int i=0;i<=n-2;i++) arr[i]=i+2;
	int comp[500];int size=0;int k=0;
	while(true){
		int p=arr[k];
		for(int i=2;i<=n;i++){
			if(i*p<=n){comp[size++]=i*p;}
			else break;
		}
		for(int j=++k;j<=n-2;j++){
			bool r= true;
			for(int a=0;a<size;a++){
				if(arr[j]==comp[a]){r=false;}
			}
			if(r==true){k=j;break;}
		}
		if(k==n-2) break;
	}
	int line=0;
	for(int i=0;i<=n-2;i++){
		bool b = true;
		int j=0;
		for(j;j<size;j++){
			if(arr[i]==comp[j]){b=false;}
		}
		if(b==true){line++;cout<<arr[i];
			if((line%5)!=0){cout<<" ";}
		}
		if(line>=5&&(line%5)==0) cout<<'\n'; 
	}
}

Grading criterion: Variable Names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor variable names
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to find all prime numbers from 2 to n (n taken as input from the user) following the procedure given below:Create an array of consecutive integers from 2 through n: (2, 3, 4, ..., n).Initially, let p equal 2, the smallest prime number. Enumerate the multiples of p by counting in increments of p from 2p to n, and mark them in the array as non-prime (these will be 2p, 3p, 4p, ...; the p itself should not be marked). Find the smallest number in the array greater than p that is not marked. If there was no such number, stop. Otherwise, let p now be equal to this new number (which will be the next prime number), and repeat from step 3.When the algorithm terminates, the numbers remaining not marked in the array are all the primes below n. Your program should print out all prime numbers from 2 to n. You do not need to use functions in this task (you may if you wish to). 

Input Format - Integer n.
Output Format - Print out the prime numbers with a space in between. After every five prime numbers print a newline character for ease of reading. 

Constraints
n >= 2 and n <= 500

Student submission:
#include<iostream>
#include<cmath>
using namespace std;
int main(){
int n;
cin>>n;
int a[n-1];
for (int i=0; i<n-1;i++)
  {
  a[i]=2+i;//inputting all numbers from 2 to n into an array with initial p=a[0]=2
  }
int b[n-1];
for (int i=0; i<n-1; i++)
  {
  b[i]=0;//initialising all to 0, this will count number of factors of a given number(a[i]) from 2 to itself-1 so if no. is prime, its 0. 
  }
for (int i=0; i<n-1; i++)
  {
  if (b[i]==0)//we only want p to be numbers which are unmarked.I can do int p=a[i], but its extra code serving no purpose whatsoever.I think its understood that p takes the value of a[i] for every unmarked i.
    {
    for (int j=2; a[i]*j<=n;j++)//j is the multiplier with p, so it has to start from 2, it has to be upto =n cuz otherwise last element wont be checked.
      {
      for (int k=i+1; k<n-1; k++)//this is just to compare to other elements in array
        {
        if (j*a[i]==a[k]) {b[k]++;}//if multiplier*p=some element of array, mark that element
        }
      }
    }
  }

//int d=1;//for some reason(probably because I am stupid) this algorathim does not check if last element of array ie n itself is prime 
//for (int i=a[n-2]; i>1; i--)//so i implemented a code to check that bahaar se
//nevermind i managed to fix it, leaving this here for no reason whatsoever. 
  //{
  //if ((a[n-2]%i)==0) {d++;}
  //}
//if (d==1) {b[n-2]=0;}
//else {b[n-2]=1;}


int c=0;//cuz every 5 element is printed on new line
for (int i=0; i<n-1; i++)
  {
  if (b[i]==0)//only prints prime nos. 
    {
    if (c%5<4) {cout<<" "<<a[i]; c++;}//this is definitely not best way of doing this, but its the first one that came to mind so :P
    else {cout<<" "<<a[i]; cout<<endl; c++;}//as a bonus, c is no. of prime nos <=n! (found this out using gdb)
    }
  }
}

Grading criterion: Variable Names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor variable names
Rating D: 0
Assigned grade: A
Problem: Write a C++ program to find all prime numbers from 2 to n (n taken as input from the user) following the procedure given below:Create an array of consecutive integers from 2 through n: (2, 3, 4, ..., n).Initially, let p equal 2, the smallest prime number. Enumerate the multiples of p by counting in increments of p from 2p to n, and mark them in the array as non-prime (these will be 2p, 3p, 4p, ...; the p itself should not be marked). Find the smallest number in the array greater than p that is not marked. If there was no such number, stop. Otherwise, let p now be equal to this new number (which will be the next prime number), and repeat from step 3.When the algorithm terminates, the numbers remaining not marked in the array are all the primes below n. Your program should print out all prime numbers from 2 to n. You do not need to use functions in this task (you may if you wish to). 

Input Format - Integer n.
Output Format - Print out the prime numbers with a space in between. After every five prime numbers print a newline character for ease of reading. 

Constraints
n >= 2 and n <= 500

Student submission:
#include<iostream>
using namespace std;
int main()
{int n; cin>>n;
int arr[n-1];
for(int i=0;i<n-1;i++)
{arr[i]=i+2;}
int p=2;int k;
for(int j=2;j<=n/p;j++)
{ k=p*j;
for(int i=0;i<n-1;i++)
{if(k==arr[i]) arr[i]=1;}
}
p=3;
for(int j=2;j<=n/p;j++)
{ k=p*j;
for(int i=0;i<n-1;i++)
{if(k==arr[i]) arr[i]=1;}}
p=5;
for(int j=2;j<=n/p;j++)
{ k=p*j;
for(int i=0;i<n-1;i++)
{if(k==arr[i]) arr[i]=1;}}
p=7;
for(int j=2;j<=n/p;j++)
{ k=p*j;
for(int i=0;i<n-1;i++)
{if(k==arr[i]) arr[i]=1;}}
p=11;
for(int j=2;j<=n/p;j++)
{ k=p*j;
for(int i=0;i<n-1;i++)
{if(k==arr[i]) arr[i]=1;}
}
p=13;
for(int j=2;j<=n/p;j++)
{ k=p*j;
for(int i=0;i<n-1;i++)
{if(k==arr[i]) arr[i]=1;}
}







for(int i=0;i<n-1;i++)
{if(arr[i]!=1) cout<<arr[i]<<" ";}
}

Grading criterion: Variable Names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor variable names
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to find all prime numbers from 2 to n (n taken as input from the user) following the procedure given below:Create an array of consecutive integers from 2 through n: (2, 3, 4, ..., n).Initially, let p equal 2, the smallest prime number. Enumerate the multiples of p by counting in increments of p from 2p to n, and mark them in the array as non-prime (these will be 2p, 3p, 4p, ...; the p itself should not be marked). Find the smallest number in the array greater than p that is not marked. If there was no such number, stop. Otherwise, let p now be equal to this new number (which will be the next prime number), and repeat from step 3.When the algorithm terminates, the numbers remaining not marked in the array are all the primes below n. Your program should print out all prime numbers from 2 to n. You do not need to use functions in this task (you may if you wish to). 

Input Format - Integer n.
Output Format - Print out the prime numbers with a space in between. After every five prime numbers print a newline character for ease of reading. 

Constraints
n >= 2 and n <= 500

Student submission:
#include<iostream>
using namespace std;
int findsm(int *a,int n,int &p){
                         int index=-1;
                         for(int i=0;i<n-1;i=i+1){if(a[i]!=0 && a[i]>p){index=i; break;}}
                         return index;
                        }
void mark(int *a,int n,int &p){
                               for(int i=2;i*p<=n;i=i+1){a[i*p-2]=0;
                               }
                               int ind=findsm(a,n,p);
                               if(ind==-1){return;}
                               else{p=ind+2;}
                               mark(a,n,p);
                               }                        
int main(){
int n; cin>>n;
int arr[n-1];
for(int j=0;j<n-1;j=j+1){arr[j]=j+2;}
int p=2;
mark(arr,n,p);
int i=0;
for(int j=0;j<n-1;j=j+1){if(arr[j]!=0){if(i%5==0){cout<<endl;}
                                        i=i+1;
                                        cout<<arr[j]<<" ";}}
    
}

Grading criterion: Variable Names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor variable names
Rating D: 0
Assigned grade: A
Problem: Write a C++ program to find all prime numbers from 2 to n (n taken as input from the user) following the procedure given below:Create an array of consecutive integers from 2 through n: (2, 3, 4, ..., n).Initially, let p equal 2, the smallest prime number. Enumerate the multiples of p by counting in increments of p from 2p to n, and mark them in the array as non-prime (these will be 2p, 3p, 4p, ...; the p itself should not be marked). Find the smallest number in the array greater than p that is not marked. If there was no such number, stop. Otherwise, let p now be equal to this new number (which will be the next prime number), and repeat from step 3.When the algorithm terminates, the numbers remaining not marked in the array are all the primes below n. Your program should print out all prime numbers from 2 to n. You do not need to use functions in this task (you may if you wish to). 

Input Format - Integer n.
Output Format - Print out the prime numbers with a space in between. After every five prime numbers print a newline character for ease of reading. 

Constraints
n >= 2 and n <= 500

Student submission:
#include<iostream>
using namespace std;

int main()
{int n,i,count=0;
cin>>n;
int a[n-1];
bool flag=true;
for(i=0;i<n-1;i++)
a[i]=i+2;
int p=2;
while(flag)
{flag=false;
int temp=2*p;
while(temp<=n)
{for(i=0;i<n-1;i++)
{if (a[i]==temp)
a[i]=0;//marking the array element  as non prime by making it zero
}
temp=temp+p;
}
for(i=p-1;i<n-1;i++)
{if(a[i]!=0)
{p=a[i];
flag=true;
break;
}
}
}

for(i=0;i<n-1;i++)\
{if (a[i]!=0)
{cout<<a[i]<<" ";
count++;

if(count%5==0)
cout<<endl;
}
}
}

Grading criterion: Variable Names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor variable names
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to find all prime numbers from 2 to n (n taken as input from the user) following the procedure given below:Create an array of consecutive integers from 2 through n: (2, 3, 4, ..., n).Initially, let p equal 2, the smallest prime number. Enumerate the multiples of p by counting in increments of p from 2p to n, and mark them in the array as non-prime (these will be 2p, 3p, 4p, ...; the p itself should not be marked). Find the smallest number in the array greater than p that is not marked. If there was no such number, stop. Otherwise, let p now be equal to this new number (which will be the next prime number), and repeat from step 3.When the algorithm terminates, the numbers remaining not marked in the array are all the primes below n. Your program should print out all prime numbers from 2 to n. You do not need to use functions in this task (you may if you wish to). 

Input Format - Integer n.
Output Format - Print out the prime numbers with a space in between. After every five prime numbers print a newline character for ease of reading. 

Constraints
n >= 2 and n <= 500

Student submission:
#include <simplecpp>
main_program {
int n=2;
int a[n];
int c=1;
cin>> a[n];
a[0]=2;{
int*p=a;
int b= (2*c-2); 
while (true)
for (int i=2; i<n; i++) {
if (c== a[b] )
return a[c] = 0 ; 
}
}
cout<< a[n] ;
}

Grading criterion: Variable Names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor variable names
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to find all prime numbers from 2 to n (n taken as input from the user) following the procedure given below:Create an array of consecutive integers from 2 through n: (2, 3, 4, ..., n).Initially, let p equal 2, the smallest prime number. Enumerate the multiples of p by counting in increments of p from 2p to n, and mark them in the array as non-prime (these will be 2p, 3p, 4p, ...; the p itself should not be marked). Find the smallest number in the array greater than p that is not marked. If there was no such number, stop. Otherwise, let p now be equal to this new number (which will be the next prime number), and repeat from step 3.When the algorithm terminates, the numbers remaining not marked in the array are all the primes below n. Your program should print out all prime numbers from 2 to n. You do not need to use functions in this task (you may if you wish to). 

Input Format - Integer n.
Output Format - Print out the prime numbers with a space in between. After every five prime numbers print a newline character for ease of reading. 

Constraints
n >= 2 and n <= 500

Student submission:
#include<iostream>
using namespace std;

int minfun(int *arr, int p, int n)
{
 int res = p-1;
 for(int i = p-1; i<n-1; i++)
 {
   if(arr[i] <= arr[res]){res = i;}
 }
 return res;
}


int main()
{
  int n; cin>>n;
  int arr[n-1];
  for(int i=0; i<n-1; i++)
  {
    arr[i] = i+2;
  }
  int p = 2, x = 2;
  while(p < n)
  {
    while(x*p <= n)
    {
      arr[x*p-2] = 1000;
      x++;
    }
    p = arr[minfun(arr, p, n)];
    x = 2;
  }
  int counter = 0;
  for(int i=0; i<n-1; i++)
  {
    if(arr[i] != 1000)
    {
       cout<<arr[i];
       counter++;
       if(counter%5 == 0){cout<<endl;}
       else{cout<<" ";}
    }
  }

return 0;
}

Grading criterion: Variable Names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor variable names
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to find all prime numbers from 2 to n (n taken as input from the user) following the procedure given below:Create an array of consecutive integers from 2 through n: (2, 3, 4, ..., n).Initially, let p equal 2, the smallest prime number. Enumerate the multiples of p by counting in increments of p from 2p to n, and mark them in the array as non-prime (these will be 2p, 3p, 4p, ...; the p itself should not be marked). Find the smallest number in the array greater than p that is not marked. If there was no such number, stop. Otherwise, let p now be equal to this new number (which will be the next prime number), and repeat from step 3.When the algorithm terminates, the numbers remaining not marked in the array are all the primes below n. Your program should print out all prime numbers from 2 to n. You do not need to use functions in this task (you may if you wish to). 

Input Format - Integer n.
Output Format - Print out the prime numbers with a space in between. After every five prime numbers print a newline character for ease of reading. 

Constraints
n >= 2 and n <= 500

Student submission:
#include<iostream>
#include<cmath>
using namespace std;
void mark(int n,int x,int *a)
{
for (int i=2;i*x<=n;i++){
if (a[x*i-2]!=0) a[x*i-2]=0;
}
}
int main(){
int n,l=0;
cin>>n;
int a[n-1];
for (int i=0;i<n-1;i++){
a[i]=i+2;
}
for (int i=0;i<n-1;i++){
if (a[i]!=0){
cout<<a[i]<<" ";
l++;
if (l%5==0)cout<<endl;
mark(n,a[i],a);
}
}
}

Grading criterion: Variable Names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor variable names
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to find all prime numbers from 2 to n (n taken as input from the user) following the procedure given below:Create an array of consecutive integers from 2 through n: (2, 3, 4, ..., n).Initially, let p equal 2, the smallest prime number. Enumerate the multiples of p by counting in increments of p from 2p to n, and mark them in the array as non-prime (these will be 2p, 3p, 4p, ...; the p itself should not be marked). Find the smallest number in the array greater than p that is not marked. If there was no such number, stop. Otherwise, let p now be equal to this new number (which will be the next prime number), and repeat from step 3.When the algorithm terminates, the numbers remaining not marked in the array are all the primes below n. Your program should print out all prime numbers from 2 to n. You do not need to use functions in this task (you may if you wish to). 

Input Format - Integer n.
Output Format - Print out the prime numbers with a space in between. After every five prime numbers print a newline character for ease of reading. 

Constraints
n >= 2 and n <= 500

Student submission:
#include<iostream>
using namespace std;

int main(){

int n;
int a[n-1];
cin >> n;

for(int i=0;i<n-1;i++){a[i]=i+2;}

int *npr1;
for(int i=2;i<n-1;i++){

  for(int j=2;j<(n/i)+1;j++){
  
    npr1[j-2]=j*a[i-2];
  }
}
for(int i=0;i<n-1;i++){
 
  if(npr1!=a+i){cout << a[i] << " ";}
}

}

Grading criterion: Variable Names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor variable names
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to find all prime numbers from 2 to n (n taken as input from the user) following the procedure given below:Create an array of consecutive integers from 2 through n: (2, 3, 4, ..., n).Initially, let p equal 2, the smallest prime number. Enumerate the multiples of p by counting in increments of p from 2p to n, and mark them in the array as non-prime (these will be 2p, 3p, 4p, ...; the p itself should not be marked). Find the smallest number in the array greater than p that is not marked. If there was no such number, stop. Otherwise, let p now be equal to this new number (which will be the next prime number), and repeat from step 3.When the algorithm terminates, the numbers remaining not marked in the array are all the primes below n. Your program should print out all prime numbers from 2 to n. You do not need to use functions in this task (you may if you wish to). 

Input Format - Integer n.
Output Format - Print out the prime numbers with a space in between. After every five prime numbers print a newline character for ease of reading. 

Constraints
n >= 2 and n <= 500

Student submission:
#include<simplecpp>
void remul(int m,int*a,int n){
for(int y=2;y<n+1;y++){
	if(y*m<=n+1){a[y*m-2]=0;}}

}
int main(){
int n;
cin>>n;
int a[n-1];
for(int x=2;x<n+1;x++){
	a[x-2]=x;}

for(int x=2;x<n+1;x++){
	remul(x,a,n-1);}
int c=1;
for(int x=0;x<n-1;x++){if( c%5==0){if(a[x]!=0){cout<<a[x]<<endl;c=c+1;}}
	else{if(a[x]!=0){cout<<a[x]<<" ";c=c+1;}}
		}

}

Grading criterion: Variable Names
Rating A: Good Variable Names
Rating B: Ok Variable Names
Rating C: Poor variable names
Rating D: 0
Assigned grade: B