Home

Learn Programming & Prepare for NPTEL Exams... Swayam Solver is your one-stop destination for NPTEL exam preparation.

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

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




  Please scroll down for latest Programs ðŸ‘‡ 





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. 
1
#include<stdio.h>
2
int main()
3
{
4
  float t[100]={10,15,18,22,30}, v[100]={22,26,35,48,68};
5
  float a; //Value of the t to find the respective value of v(t)
6
  scanf("%f", &a);  // This will be taken from test cases
7
int i,j;
8
float b, c, k =0;
9
for(i=0; i<5; i++)
10
   {
11
      b=1;
12
      c=1;
13
      for(j=0; j<5; j++)
14
        {
15
           if(j!=i)
16
             {
17
               b=b*(a-t[j]);
18
               c=c*(t[i]-t[j]);
19
              }
20
            }
21
        k=k+((b/c)*v[i]);
22
        }
0
printf("The respective value of the variable v is: %.2f", k);
1
  return 0;
2
}
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 Program-02

Due on 2024-04-11, 23:59 IST
Select the Language for this assignment. 
1
#include<stdio.h>
2
float func(float x);
3
int main()
4
{
5
  int n=10; //Taking n=10 sub intervals
6
  float a,b,integral; //integral is the integration result
7
  scanf("%f",&a); // initial limit taken from test case 
8
  scanf("%f",&b); // Final limit taken from test case
9
10
//Use the printf statement as printf("The integral is: %0.6f\n",integral);
11
int i;
12
float h,x, sum=0;  
13
if(b>a)
14
  h=(b-a)/n;
15
  else
16
  h=-(b-a)/n;
17
  for(i=1;i<n;i++){
18
    x=a+i*h;
19
    sum=sum+func(x);
20
  }
21
  integral=(h/2)*(func(a)+func(b)+2*sum);
22
  printf("The integral is: %0.6f",integral);
23
  return 0;
24
}
25
float func(float x)
26
{
27
  return x*x;
28
}
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 Program-03

Due on 2024-04-11, 23:59 IST
Select the Language for this assignment. 
1
#include<stdio.h>
2
float func(float x,float y);
3
int main()
4
{
5
    float m1,m2,m3,m4,m,h=0.3;
6
    float x0 = 0.3, y0 = 5, xn;
7
    // xn will be taken from test cases
8
    scanf("%f",&xn);
9
10
//Use the printf statement as: printf("y=%f",y0);  // Final output
11
while(x0<xn)
12
    {
13
        m1=func(x0,y0);
14
        m2=func((x0+h/2.0),(y0+m1*h/2));
15
        m3=func((x0+h/2.0),(y0+m2*h/2));
16
        m4=func((x0+h),(y0+m3*h));
17
        m=((m1+2*m2+2*m3+m4)/6);
18
        y0=y0+m*h;
19
        x0=x0+h;
20
    }
21
    printf("y=%f",y0);  // Final output
22
    return 0;
23
}
24
float func(float x,float y)
25
{
26
    float m;
27
    m=(x*(x+1)-3*y*y*y)/10;
28
    return m;
29
}
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 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. 
1
#include <stdio.h>
2
int checkPrime(int, int); //Function to check prime or not 
3
4
int main()
5
{
6
    int num, check;
7
    scanf("%d", &num); //The number is taken from test case data
8
    check = checkPrime(num, num/2);
9
    if (check == 1)
10
    {
11
        printf("%d is a prime number\n", num);
12
    }
13
    else
14
    {
15
        printf("%d is not a prime number\n", num);
16
    }
17
    return 0;
18
}
19
int checkPrime(int num, int i)
20
{
21
    if (i == 1)
22
    {
23
        return 1;
24
    }
25
    else
26
    {
27
       if (num % i == 0)
28
       {
29
         return 0;
30
       }
31
       else
32
       {
33
         return checkPrime(num, i - 1);
34
       }
35
    }
36
}
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











Week-12: Program-01

Due on 2024-04-18, 23:59 IST
Write a program in C to find the factorial of a given number using pointers.
Your last recorded submission was on 2024-04-06, 10:44 IST
Select the Language for this assignment. 
1
#include <stdio.h>
2
void findFact(int, long int*);
3
int main()
4
{
5
        long int fact; //factorial of the number
6
        int num1; 
7
        scanf("%d",&num1); //The number is taken from test data
8
9
         findFact(num1, &fact);
10
         printf("The Factorial of %d is : %ld\n",num1, fact);
11
         return 0;
12
        }
13
void findFact(int n, long int *f)
14
        {
15
        int i;
16
17
       *f =1;
18
       for(i=1;i<=n;i++)
19
       *f=*f*i;
20
       }
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
5
The Factorial of 5 is : 120
The Factorial of 5 is : 120\n
Passed after ignoring Presentation Error
Test Case 2
15
The Factorial of 15 is : 1307674368000
The Factorial of 15 is : 1307674368000\n
Passed after ignoring Presentation Error






Week-12: Program-02

Due on 2024-04-18, 23:59 IST
Write a C program to print the Record of the Student Merit wise. Here a structure variable is defined which contains student rollno, name and score.
Select the Language for this assignment. 
1
#include<stdio.h>
2
struct student
3
{
4
int rollno;
5
char name[20];
6
int score;
7
};
8
void main()
9
{
10
struct student s[20];
11
int i, n;
12
13
scanf("%d" ,&n); //No. of Students taken from test data
14
// Roll no., Name and Score of n students are taken from test data
15
for(i=0;i<n;i++)
16
{
17
scanf("%d", &s[i].rollno);
18
scanf("%s", s[i].name);
19
scanf("%d", &s[i].score);
20
}
21
//Complete the program so that merit list is printed in descending order
22
struct student temp;
23
int j;
24
for(i=0;i<n-1;i++)
25
{
26
for(j=0;j<n-1;j++)
27
{
28
if(s[j].score<s[j+1].score)
29
{
30
temp=s[j];
31
s[j]=s[j+1];
32
s[j+1]=temp;
33
}
34
}
35
}
0
printf("The Merit List is :\n");
1
for(i=0;i<n;i++)
2
{
3
printf("%d", s[i].rollno);
4
printf("  %s", s[i].name);
5
printf("  %d\n", s[i].score);
6
}
7
8
}
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
3
1
Santanu
700
2
Aparna
550
3
Vivek
900
The Merit List is :\n
3  Vivek  900\n
1  Santanu  700\n
2  Aparna  550
The Merit List is :\n
3  Vivek  900\n
1  Santanu  700\n
2  Aparna  550\n
Passed after ignoring Presentation Error







Week-12: Program-03

Due on 2024-04-18, 23:59 IST
Write a C program to store n elements using Dynamic Memory Allocation - calloc() and find the Largest element
Select the Language for this assignment. 
1
#include <stdio.h>
2
#include <stdlib.h>
3
4
int main()
5
{
6
    int n; 
7
    float *element;
8
9
    scanf("%d", &n); //Total number of elements
10
11
    // Allocate the memory for 'n' number of elements. 
12
    //Then take the elements as input from test data
13
element = (float*) calloc(n, sizeof(float));
14
15
    if(element == NULL)
16
    {
17
        printf("Error!!! memory not allocated.");
18
        exit(0);
19
    }
20
21
    // Stores the number entered by the user.
22
    int i;
23
    for(i = 0; i < n; ++i)
24
    {
25
        scanf("%f", element + i);
26
    }
27
28
 // find the largest
29
    for(i = 1; i < n; ++i)
30
    {
31
       if(*element < *(element + i))
32
         *element = *(element + i);
33
    }
34
35
36
    printf("Largest element = %.2f", *element);
37
38
    return 0;
39
}
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
5
200
300
500
100
400
Largest element = 500.00
Largest element = 500.00
Passed







Week-12: Program-04

Due on 2024-04-18, 23:59 IST
Write a C program to add two distance given as input in feet and inches.
Select the Language for this assignment. 
1
#include<stdio.h>
2
3
struct Distance{
4
    int feet;
5
    int inch;
6
}d1,d2,sum;
7
8
int main()
9
    {
10
    //Enter 1st distance
11
    scanf("%d",&d1.feet); 
12
    scanf("%d",&d1.inch);
13
    //Enter 2nd distance
14
    scanf("%d",&d2.feet);
15
    scanf("%d",&d2.inch);
16
    sum.feet=d1.feet+d2.feet;
17
    sum.inch=d1.inch+d2.inch;
18
 
19
/* If inch is greater than 12, converting it to feet. */
20
    if (sum.inch>=12)
21
    {
22
        sum.inch=sum.inch-12;
23
        ++sum.feet;
24
    }
0
printf("Sum of distances = %d feet %d inches",sum.feet,sum.inch);
1
    return 0;
2
}
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
40
11
10
11
Sum of distances = 51 feet 10 inches
Sum of distances = 51 feet 10 inches
Passed
Test Case 2
10
5
20
5
Sum of distances = 30 feet 10 inches
Sum of distances = 30 feet 10 inches
Passed






































No comments:

Post a Comment

Keep your comments reader friendly. Be civil and respectful. No self-promotion or spam. Stick to the topic. Questions welcome.