# Problem Solving Through Programming In C Week 11

**Session: JAN-APR 2023**

**Course Name: Problem Solving Through Programming In C**

**Course Link: Click Here**

**These are Problem Solving Through Programming In C Assignment 11 Answers**

**Q1. Interpolation is a process for**

a) extracting feasible data set from a given set of data

b) finding a value between two points on a line or curve.

c) removing unnecessary points from a curve

d) all of the mentioned

**Answer: b) finding a value between two points on a line or curve.**

**Q2. Given two data points (a, f (a)) and (b, f(b). the linear Lagrange polynomial f (x) that passesthrough these two points are given as**

a) f(x) = (x-a/a-b)f(a) + (x-a/a-b)f(b)

b) f(x) = (x/a-b)f(a) + (x/b-a)f(b)

c) f(x) = f(a) + (f(b)-f(a)/b-a)f(b)

d) f(x) = (x-b/a-b)f(a) + (x-a/b-a)f(b)

**Answer: d) f(x) = (x-b/a-b)f(a) + (x-a/b-a)f(b)**

**These are Problem Solving Through Programming In C Assignment 11 Answers**

**Q3. A Lagrange polynomial passes through three data points as given below**

**The polynomial is determined as f(x) = L0 (x). (15.35) + L₁ (x). (9.63) + L₂(x). (3.74) The value of f(x) at x = 7 is**

a) 12.78

b) 13.08

c) 14.12

d) 11.36

**Answer: b) 13.08**

**Q4. The value of f 1.5 0 xe²x dx by using one segment trapezoidal rule is (upto four decimal places) The value of**

Answer: 22.5962

**These are Problem Solving Through Programming In C Assignment 11 Answers**

**Q5. Accuracy of the trapezoidal rule increases when**

a) integration is carried out for sufficiently large range

b) instead of trapezoid, we take rectangular approximation function

c) number of segments are increased

d) integration is performed for only integer range

**Answer: c) number of segments are increased**

**Q6. Solve the ordinary differential equation below using Runge-Kutta 4th order method. Step sizeh=0.2.5dy/dx +xy3 = cos(x),y(0) = 3The value of y(0.2) is (upto two decimal points)**

a) 2.86

b) 2.93

c)3.13

d) 3.08

**Answer: b) 2.93**

**These are Problem Solving Through Programming In C Assignment 11 Answers**

**Q7. Which of the following cannot be a structure member?**

a) Another structure

b) function

c) array

d) none of the above

**Answer: b) function**

**Q8. Match the followingA. Newton Method 1. IntegrationB. Lagrange Polynomial 2. Root findingC. Trapezoidal Method 3. Differential EquationD. Runge Kutta Method 4. Interpolation**

a) A-2, B-4, C-1, D-3

b) A-3, B-1, C-2, D-4

c) A-1, B-4, C-3, D-2

d) A-2, B-3, C-4, D-1

**Answer: a) A-2, B-4, C-1, D-3**

**These are Problem Solving Through Programming In C Assignment 11 Answers**

**Q9. The value of (3 1 ex(In x) dx calculated using the Trapezoidal rule with five subintervals is (* rangeis given in output rather than single value to avoid approximation error)**

a) 12.56 to 12.92

b) 13.12 to 13.66

c) 14.24 to 14.58

d) 15.13 to 15.45

**Answer: c) 14.24 to 14.58**

**Q10. Consider the same recursive C function that takes two arguments unsigned int func(unsigned int n, unsigned int r){if (n >0) retum (n%r + func (n/r, r));else return 0;}What is the return value of the function foo when it is called as func(513, 2)?**

a) 9

b) 8

c) 5

d) 2

**Answer: d) 2**

**These are Problem Solving Through Programming In C Assignment 11 Answers**

### Problem Solving Through Programming In C Programming Assignment

**Question 1**

**The velocity of a car at different time instant is given as**

**A linear Lagrange interpolant is found using these data points. Write a C program to find the velocity of the car at different time instants. (Taken from test cases)**

**Solution:**

```
int i,j;
float b, c, k =0;
for(i=0; i<5; i++)
{
b=1;
c=1;
for(j=0; j<5; j++)
{
if(j!=i)
{
b=b*(a-t[j]);
c=c*(t[i]-t[j]);
}
}
k=k+((b/c)*v[i]);
}
```

**Question 2**

**Write a C program to find (ba x2dx using Trapezoidal rule with 10 segments between a and b. The values of a and b will be taken from test cases.**

**Solution:**

```
int i;
float h,x, sum=0;
if(b>a)
h=(b-a)/n;
else
h=-(b-a)/n;
for(i=1;i<n;i++){
x=a+i*h;
sum=sum+func(x);
}
integral=(h/2)*(func(a)+func(b)+2*sum);
printf("The integral is: %0.6f\n",integral);
return 0;
}
float func(float x)
{
return x*x;
}
```

**These are Problem Solving Through Programming In C Assignment 11 Answers**

**Question 3**

**Write a C program to solve the following differential equation using Runge-Kutta method. Step size h=0310dy/dx + 3y^3 = x(x+1),y(0.3)=5Find y(x) for different values of x as given in the test cases.**

**Solution:**

```
float m1,m2,m3,m4,m,h=0.3;
float x0 = 0.3, y0 = 5;
while (x0 < xn)
{
m1 = func(x0, y0);
m2 = func((x0 + h/2.0), (y0 + m1*h/2));
m3 = func(x0 + h/2.0, (y0 + m2*h/2));
m4 = func((x0 + h), (y0 + m3*h));
m=((m1+2*m2+2*m3+m4)/6);
y0=y0+m*h;
x0=x0+h;
}
printf("y=%.6f",y0);
return 0;
}
float func(float x,float y)
{
float m;
m=(x*(x+1)-3*y*y*y)/10;
return m;
}
```

**These are Problem Solving Through Programming In C Assignment 11 Answers**

**Question 4**

**Write a C program to check whether the given input number is Prime number or not using recursion. The input is an integer and output should print whether the integer is prime or not. (Note that you have to use recursion).**

**Solution:**

```
int checkPrime(int num, int i)
{
if (i == 1)
{
return 1;
}
else
{
if (num % i == 0)
{
return 0;
}
else
{
return checkPrime(num, i - 1);
}
}
}
```

**These are Problem Solving Through Programming In C Assignment 11 Answers**

More Weeks of Problem Solving Through Programming In C: Click Here

More Nptel courses: https://progiez.com/nptel