Problem: The Taylor series of a function f(x) about a is given by f(x) = f(a) + (x-a) f(1)(a) + [(x-a)2/2! ] f(2)(a) + [(x-a)3/3! ] f(3)(a) + ... + (x-a)n/n! f(n)(a) + ...Here n is the number of terms of the Taylor series expansion and f(n)(a)is the n-th derivative of the function f(x) evaluated at x = a. This formula (with only finitely many terms) is very accurate for x close to a.Write a C++ program that takes a, x, and n as inputs from the user and evaluates the Taylor expansion of f(x) = sin x about a up to n terms. The program should also compute the relative absolute error between the value of the Taylor expansion (let us call it ea) w.r.t. the true value which is sin(a). The formula for this is |ea - sin (a)| / |sin(a)|.The program should print the value of the Taylor expansion as well as the relative absolute error. 

Input Format - a - non zero real number, x,and an integer n
Output Format - 
Floating point numbers for the values of the Taylor expansion and the relative error
Please use before printing the approximated value and the error.
cout << fixed;      // uses fixed floating point representation
cout.precision(6);  // print six digits after the decimal point

Constraints
a not equal to zero
n is a positive integer
For higher accuracy, it is advisable for x to be close to a

Sample input and output a = pi/3 , x = pi/3 + 0.001, sin(x) is approximately 0.8

Input           1.047 1.048 100
Output            0.866426 0.000577

Note:Do not write any C++ statements for printing general messages. For example, the following should NOT be present in your program:cout << "Enter a number:",cout << "The computed answer is", etc.cout should be used to print only the computed final output. In addition, do not print unnecessary spaces unless specified in the questionPlease use cout << fixed; before printing the approximated value and the error.The solution file name should be an A_Q1.cpp

Student submission:
#include<bits/stdc++.h>
//#include<cmath>
using namespace std;
float fact(int n){
        if(n==0||n==1){return 1;}
        int f=1;
        for(int i=1; i<=n; i++){f=f*i;}
        return f;
}
int main(){ 
 double a,x;
         int n;
        cin>>a>>x>>n;
        double  z=x-a;
        double  q[n+1];
        double b[n+1];
        double c[n+1];
        //q[0]=b[0]=c[0]=0.000000;
        for(int i=1; i<=n; i++){
                for(int j=1; j<=i; j++){z=z*(x-a);}
                b[i]=z/fact(i);

        }

        for(int i=1; i<=n; i=i+4){
                c[i]=cos(a);
        }

        for(int i=2; i<=n; i=i+4){
                c[i]=-1*sin(a);
        }

        for(int i=3; i<=n; i=i+4){
                c[i]=-1*cos(a);
        }

        for(int i=4; i<=n; i=i+4){
                c[i]=sin(a);
        }

        for(int i=1; i<=n; i++){
                q[i]=b[i]*c[i];
        }

        float sum=0.000000;
        for(int i=1; i<=n; i++){
                sum+=q[i];
        }
sum=sum+sin(a);
        double act=sin(a);
        double err=fabs(sum-act)/fabs(act);
        cout<<fixed;
        cout.precision(6);
        cout<<sum<<" "<<err;
}

Grading criterion: Nth derivative computed correctly
Rating A: Fully correct
Rating B: Almost correct
Rating C: Tried something in somewhat right direction.
Rating D: Totally wrong
Assigned grade: A