CBNST 1
CBNST 1
*/
#include <stdio.h>
#include <math.h>
int main() {
scanf("%f", &actual_value);
scanf("%f", &measured_value);
return 0;
}
OUTPUT :
/*
Name : Saurav Kumar
University Roll Number: 2103058
Section: F ( 63 )
Q.2) WAP in C to find the approximate root for the equation x3-4x-9=0 up to 2 decimal
places using Bisection method.
*/
#include <stdio.h>
#include <math.h>
float f(float x) {
return;
float c = a;
c = (a + b) / 2;
if (f(c) == 0.0) {
break;
b = c;
} else {
a = c;
}
printf("The approximate root is: %.2f\n", c);
int main() {
bisection(a, b);
return 0;
}
OUTPUT :
/*
Name : Saurav Kumar
University Roll Number: 2103058
Section: F ( 63 )
Q.3) WAP in C to find the real root for the equation cosx-3x+1=0 for 7 iterations using
iteration method.
*/
#include <stdio.h>
#include <math.h>
#define MAX_ITER 7
double equation(double x) {
double iterate(double x) {
int main() {
int iter;
x0 = 0.5;
printf("------------------------------------------\n");
printf("------------------------------------------\n");
x1 = iterate(x0);
x0 = x1;
}
printf("------------------------------------------\n");
return 0;
}
OUTPUT :
/*
Name : Saurav Kumar
University Roll Number: 2103058
Section: F ( 63 )
Q.4) WAP in C to find the root for the equation x3-3x+1=0 up to 4 decimal places using
Regula Falsi Method.
*/
#include <stdio.h>
#include <math.h>
double f(double x) {
return;
double c = a;
break;
b = c;
else
a = c;
}
int main() {
regula_falsi(a, b);
return 0;
}
OUTPUT :
/*
Name : Saurav Kumar
University Roll Number: 2103058
Section: F ( 63 )
Q.5) WAP in C to find the root for the equation x3-5x+1=0 up to 3 decimal points between
the interval (2,2.5) using Secant method.
*/
#include <stdio.h>
#include <math.h>
double f(double x) {
int iteration = 0;
do {
fx0 = f(x0);
fx1 = f(x1);
fx2 = f(x2);
x0 = x1;
x1 = x2;
iteration++;
return;
int main() {
secant(x0, x1);
return 0;
}
OUTPUT :
/*
Name : Saurav Kumar
University Roll Number: 2103058
Section: F ( 63 )
Q.6) WAP in C to find the root for the equation x- 𝑒 −𝑥 up to 3 decimal points for the interval
(1,2) using Newton Raphson method.
*/
#include <stdio.h>
#include <math.h>
double func(double x) {
return x - exp(-x);
double derivative(double x) {
return 1 + exp(-x);
int iteration = 0;
do {
fx = func(x0);
fprime = derivative(x0);
x1 = x0 - fx / fprime;
return;
x0 = x1;
iteration++;
} while (iteration < MAX_ITER);
int main() {
double x0 = 1.5;
newtonRaphson(x0);
return 0;
}
OUTPUT :
/*
Name : Saurav Kumar
University Roll Number: 2103058
Section: F ( 63 )
Q.7) WAP in C to implement Newton Forward Interpolation Method by displaying the
difference table for the given set of intervals.
*/
#include <stdio.h>
#include <math.h>
int fact(int n) {
if (n <= 1)
return 1;
printf("%.4f\t", y[i][0]);
printf("%.4f\t", y[i][j]);
}
printf("\n");
double temp = 1;
temp *= (u - i + 1) / i;
return result;
int main() {
forwardDifferenceTable(n, x, y);
printDifferenceTable(n, y);
double x0 = 1935;
return 0;
}
OUTPUT :
/*
Name : Saurav Kumar
University Roll Number: 2103058
Section: F ( 63 )
Q.8) WAP in C for Newton Backward Interpolation Method for the given table .
*/
#include <stdio.h>
#include <math.h>
printf("%.4f\t", y[i][0]);
printf("%.4f\t", y[i][j]);
printf("\n");
temp *= (u + i - 1) / i;
return result;
int main() {
backwardDifferenceTable(n, x, y);
printDifferenceTable(n, y);
double x0 = 1935;
return 0;
\
OUTPUT :
/*
Name : Saurav Kumar
University Roll Number: 2103058
Section: F ( 63 )
Q.9) WAP in C for Lagrange Interpolation Method by displaying the difference table for
the given set of intervals.
*/
#include <stdio.h>
#include <math.h>
if (j != i) {
result += term;
return result;
printf("Difference Table:\n");
printf("x\t\tf(x)\n");
}
int main() {
printDifferenceTable(n, x, y);
return 0;
}
OUTPUT :
/*
Name : Saurav Kumar
University Roll Number: 2103058
Section: F ( 63 )
6 1
Q.10) WAP in C for Trapezoidal Rule for the equation ∫0 1+𝑥 2 for 6 intervals.
*/
#include <stdio.h>
#include <math.h>
double func(double x) {
return 1 / (1 + x * x);
double h = (b - a) / n;
double x = a + i * h;
sum += 2 * func(x);
return (h / 2) * sum;
int main() {
double a = 0.0;
double b = 6.0;
int n = 6;
return 0;
}
OUTPUT :
/*
Name : Saurav Kumar
University Roll Number: 2103058
Section: F ( 63 )
6 1
Q.11) WAP in C for Simpson 1/3 Rule for the equation ∫0 1+𝑥2 for 6 intervals.
*/
#include <stdio.h>
#include <math.h>
double func(double x) {
return 1 / (1 + x * x);
double h = (b - a) / n;
double x = a + i * h;
return (h / 3) * sum;
int main() {
double a = 0.0;
double b = 6.0;
int n = 6;
return 0;
}
OUTPUT :
/*
Name : Saurav Kumar
University Roll Number: 2103058
Section: F ( 63 )
6 1
Q.12) WAP in C for Simpson 3/8 Rule for the equation ∫0 1+𝑥2 for 6 intervals.
*/
#include <stdio.h>
#include <math.h>
double func(double x) {
return 1 / (1 + x * x);
double h = (b - a) / n;
double x = a + i * h;
return (3 * h / 8) * sum;
int main() {
double a = 0.0;
double b = 6.0;
int n = 6;
return 0;
}
OUTPUT :
/*
Name : Saurav Kumar
University Roll Number: 2103058
Section: F ( 63 )
𝑑𝑦
Q.13) WAP in C for Euler’s Method for the equation 𝑑𝑥 = 𝑦 − 2𝑥 start at (x, y) = (0, 1)
with subinterval (h) = 0.4 for range 0 ≤ 𝑥 ≤ 2.
*/
#include <stdio.h>
#include <math.h>
return y - 2 * x;
int main() {
double h = 0.4;
printf("x\t\ty\n");
printf("%.1f\t\t%.6f\n", x, y);
y = y + h * f(x, y);
x = x + h;
printf("%.1f\t\t%.6f\n", x, y);
return 0;
}
OUTPUT :