NPTEL Week-11 Problem Solving Through Programming In C - Programming Assignment Oct-2023 Swayam

 

Week 11 : Programming Assignment 1

Due on 2023-10-12, 23:59 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;
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
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 : Programming Assignment 2

Due on 2023-10-12, 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;
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
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 : Programming Assignment 3

Due on 2023-10-12, 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;
    scanf("%f",&xn); //xn will be taken from test cases
 
 
//Use the printf statement as: printf("y=%f",y);
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;
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
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 : Programming Assignment 4

Due on 2023-10-12, 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);
       }
    }
}
You may submit any number of times before the due date. The final submission will be considered for grading.
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program , your assignment will not be graded and you will not see your score after the deadline.
   


 
 
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...