NPTEL Problem Solving Through Programming In C - Programming Assignment Jan-2024 Week 11

 

Week-11 Program-01

Due on 2024-04-11, 23:59 IST
Your last recorded submission was on 2024-03-30, 16:32 IST
Select the Language for this assignment. 
#include<stdio.h>
int main()
{
  float t[100]={10,15,18,22,30}, v[100]={22,26,35,48,68};
  float a; //Value of the t to find the respective value of v(t)
  scanf("%f", &a);  // This will be taken from test cases
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]);
        }
printf("The respective value of the variable v is: %.2f", k);
  return 0;
}
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
25
The respective value of the variable v is: 56.42
The respective value of the variable v is: 56.42
Passed
Test Case 2
16
The respective value of the variable v is: 28.74
The respective value of the variable v is: 28.74
Passed





Week-11 Program-02

Due on 2024-04-11, 23:59 IST
Select the Language for this assignment. 
#include<stdio.h>
float func(float x);
int main()
{
  int n=10; //Taking n=10 sub intervals
  float a,b,integral; //integral is the integration result
  scanf("%f",&a); // initial limit taken from test case 
  scanf("%f",&b); // Final limit taken from test case
 
//Use the printf statement as printf("The integral is: %0.6f\n",integral);
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",integral);
  return 0;
}
float func(float x)
{
  return x*x;
}
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
0
1
The integral is: 0.335000
The integral is: 0.335000
Passed
Test Case 2
1
3
The integral is: 8.680000
The integral is: 8.680000
Passed





Week-11 Program-03

Due on 2024-04-11, 23:59 IST
Select the Language for this assignment. 
#include<stdio.h>
float func(float x,float y);
int main()
{
    float m1,m2,m3,m4,m,h=0.3;
    float x0 = 0.3, y0 = 5, xn;
    // xn will be taken from test cases
    scanf("%f",&xn);
 
//Use the printf statement as: printf("y=%f",y0);  // Final output
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=%f",y0);  // Final output
    return 0;
}
float func(float x,float y)
{
    float m;
    m=(x*(x+1)-3*y*y*y)/10;
    return m;
}
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
0.9
y=1.777165
y=1.777165
Passed
Test Case 2
1.2
y=1.468128
y=1.468128
Passed






Week-11 Program-04

Due on 2024-04-11, 23:59 IST
Write a C program to check whether the given input number is Prime number or not using recursion. So, the input is an integer and output should print whether the integer is prime or not. Note that you have to use recursion.
Select the Language for this assignment. 
#include <stdio.h>
int checkPrime(int, int); //Function to check prime or not 
 
int main()
{
    int num, check;
    scanf("%d", &num); //The number is taken from test case data
    check = checkPrime(num, num/2);
    if (check == 1)
    {
        printf("%d is a prime number\n", num);
    }
    else
    {
        printf("%d is not a prime number\n", num);
    }
    return 0;
}
int checkPrime(int num, int i)
{
    if (i == 1)
    {
        return 1;
    }
    else
    {
       if (num % i == 0)
       {
         return 0;
       }
       else
       {
         return checkPrime(num, i - 1);
       }
    }
}
   


 
 
Public Test CasesInputExpected OutputActual OutputStatus
Test Case 1
13
13 is a prime number
13 is a prime number\n
Passed after ignoring Presentation Error
Test Case 2
40
40 is not a prime number
40 is not a prime number\n
Passed after ignoring Presentation Error



No comments

JavaFX Scene Builder

  This is an article about the JavaFX Scene Builder. You will get a short introduction about the installation and usage of the software. The...