CodeGraderBench/CodeGraderBench huggingface dataset:
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

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

double sequence(double x, double S, double epsilon){
	if(fabs((x+S/x)/2-x)<epsilon){
		return x;
	}
	return sequence((x+S/x)/2, S, epsilon);
}
int main(){
	double n, epsilon;
	cin >> n >> epsilon;
	cout << fixed;
	cout.precision(5);
	cout << sequence(1,n, epsilon) << endl;
}

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
Assigned grade: A
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

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

double square_root(double S, double epsilon, double x0)
{
	double x1 = (x0 + S/x0)/2.0;
	while(abs(x1-x0)>epsilon)
	{
		x0 = x1;
		x1 = (x1+S/x1)/2.0;
	}
	return x1;
}
int main()
{
	double S,epsilon,x0;
	cin>>S>>epsilon;
	x0 = S/2.0; //initial guess : chosen arbitrarily
	cout<<fixed;
	cout.precision(5);
	cout<<square_root(S,epsilon,x0);

}

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
Assigned grade: A
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

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


double acc(int n, int s, double x0){
    if (n==1) return x0;
    x0= acc(n-1,s,(x0+ (double)s/x0)/2);
}


void sqr(int s, double eps){

    
    int n=1;
    double ans;
    while (abs(acc(n+1,s,1)-acc(n,s,1))>eps){
        ans= acc(n+1,s,1);
        n++;
    }
    cout<<fixed;
    cout.precision(5);
    cout<<ans;
}
int main()
{
   int s;
   double eps;
   cin>>s>>eps;
   sqr(s,eps);
}

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
Assigned grade: A
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

Student submission:
#include <iostream>
using namespace std;
double ans(double s,double e){
	double xi=s/2;
	double xf=(xi + s/xi)/2;
	while(abs(xf-xi)>e){
		xi=xf;
		 xf=(xi + s/xi)/2;
	}
	return xf;
}

int main(){
	double s,e;
	cin>>s>>e;
	
	cout<<fixed;
	cout.precision(5);
	cout<<ans(s,e);
	
	return 0;
}

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
Assigned grade: A
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

Student submission:
#include<simplecpp>



main_program{
float x0=1;
float s;
cin>>s;
float x1=(x0+s/x0)/2;
float xn=x1,xn1=x0;
float ep=0.01;

float diff=xn-xn1;
if (xn-xn1<0){diff=diff*(-1);}

if (diff<ep){
	cout<<xn;
}
else if (diff>ep){
	while(diff>ep){
		float temp=xn;
		xn=(xn+s/xn)/2;
		xn1=temp;
		diff=xn-xn1;
		if (xn-xn1<0){diff=diff*(-1);}
	}
	cout<<xn;
}
}

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
Assigned grade: A
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

Student submission:
#include<iostream>

using namespace std;

int main(){
	double s,x1,x,eps=0.01;
	cin>>s>>x;
	if(s>0){
	x1=( x+(s/ x)*0.5);
	
	cout<<x1;
	}
}

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
Assigned grade: C
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

Student submission:
#include<iostream>
#include<cmath>
using namespace std;
double squareroot(double S, double epsilon) {
float x=S;
float _x;
do {
_x = (x + S/x)/2;
float xx =(_x + S/_x)/2;
x = _x;
_x=xx;
}
while (fabs(_x -x)>epsilon);
return x;
}
int main() {
double a,b;
cin>>a>>b;
cout << squareroot(a,b);
}

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
Assigned grade: B
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

Student submission:
#include<iostream>
#include<cmath>
using namespace std;
float sqrtfunct(float S,float epsilon);
int main()
{
float S,epsilon;
cin>>S>>epsilon;
float p=sqrtfunct(S,epsilon);
cout<<fixed;
cout.precision(5);
cout<<p;
}

float sqrtfunct(float S, float epsilon)
{
float xn,xn1=2;

do
{
xn=xn1;
xn1=(xn+float(S)/float(xn))/float(2);
}
while(abs(xn1-xn)>epsilon);
return xn1;
}

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
Assigned grade: A
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

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

double baby(double x,double s)
{return (x+s/x)/2;}

int main(){
double s,e;
cin>>s>>e;
double x1=s,x2;

while(fabs(x2-x1)>e)
{x2=x1;
 x1=baby(x1,s);
}

cout<<fixed;
cout.precision(5);

cout<<x2;
}

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
Assigned grade: A
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

Student submission:
#include<simplecpp>
#include<cmath>
double squareroot(double x){ 
double y= x;double y1=0;
	while(fabs(y1-y)>0.0000001){ 
	y1=y;
	y=0.5*(y+ float(x)/y);
	}return y;
}
main_program{ 
double s;cin>>s;
	cout<<fixed;
	cout.precision(5);
	cout<<squareroot(s);
}

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
Assigned grade: B
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

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

float babylonian(double  x,double  eps,double s)
{  double n=0;
   while(abs(n-x) > eps)
   {     n=x;
	x=(x+s/x)/2;     
    
   }
    return x;
}
int main(){
double s,eps,x=4;
cin>>s;
cin>>eps;
cout<<babylonian(x,eps,s);

}

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
Assigned grade: A
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

Student submission:
#include<iostream>
using namespace std;
double root( double S, double eps){
double j;
for(j=1;(j*j)<=S;j++){}
double y=j;
double x=(j+S/j)/2;
while (x-y>eps){
y=x;
x=(y+S/y)/2;}
cout<<x;}
int main(){
double S;
double eps;
cin>>S>>eps;
cout<<root(S,eps)}

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
Assigned grade: C
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

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

double sqrt(double s){
  double e=0.00001;
 double x0=s/3;
 double x1=(x0+s/x0)/2;

while(fabs(x0-x1)>e){
x0=x1;
x1=(x1+s/x1)/2;
}
return x0;
}
int main(){
 double s;
cin>>s;

cout<<sqrt(s);
}

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
Assigned grade: B
Problem: An iterative method, called the Babylonian method, for finding square roots, was known to the ancient Babylonians (1500 BC) and Greeks (100 AD) long before Newton invented his general procedure. Here's how it works. Suppose you are given any positive number S. To find the square root of S, do the following: Make an initial guess. Guess any positive number x0.Improve the guess. Apply the formula x1 = (x0 + S / x0) / 2. The number x1 is a better approximation to sqrt(S).Iterate until convergence. Apply the formula xn+1 = (xn + S / xn) / 2 until the process converges. Convergence is achieved when the absolute difference between xn+1  and xn falls below some user specified epsilon.Your job is to write a C++ program containing a function that determines the approximate square root of the number S (taken as input) up to some desired precision epsilon. To get credit, you must write a function.

Input Format - S should be greater than 0. Epsilon should be small in value. 
Output Format - Print the value of the square root up to 5 decimal places.  

Constraints
S > 0, 
epsilon <= 0.01.

Student submission:
#include<iostream>
using namespace std;
void sqrt(double s,double eps){
int i;
char flag;
double x0,x1;
      for(i=0;i<s;i++){if(i*i*1.0==s){x0=i-1;break;}
		      else if(i*i>s){x0=(i-1);break;}
	         }
	x1=i+1;
while(flag){x1= double(x0+(double(s)/double(x0)))/2;
	flag=(x1-x0)>eps;
	x0=x1;
           }
cout<<fixed;
cout.precision(5);
cout<<x0;
				}
int main(){
double s,eps;
cin>>s;
cin>>eps;
sqrt(s,eps);
          }

Grading criterion: Whether babylonian method is correctly implemented
Rating A: fully correct
Rating B: Almost correct
Rating C: tried in right somewhat direction
Rating D: totally wrong
Assigned grade: B