NPTEL PROGRAMMING ASSIGNMENTS
Problem Solving Through Programming in C
Week-11 Program-01
Due Date of Submission 2022-04-14, 23:59 ISTThe velocity of a car at different time instant is given as
Time(t)
10
15
18
22
30
Velocity v(t)
22
26
35
48
68
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.
#include<stdio.h>
int main()
{
float t[100]={10,15,18,22,30}, v[100]={22,26,35,48,68};
float a;
scanf("%f", &a);
Time(t) |
10 |
15 |
18 |
22 |
30 |
Velocity v(t) |
22 |
26 |
35 |
48 |
68 |
#include<stdio.h>
int main()
{
float t[100]={10,15,18,22,30}, v[100]={22,26,35,48,68};
float a;
scanf("%f", &a);
int main()
{
float t[100]={10,15,18,22,30}, v[100]={22,26,35,48,68};
float a;
scanf("%f", &a);
printf("The respective value of the variable v is: %.2f", k);
return 0;
}
return 0;
}
Week-11 Program-02
Due Date of Submission 2022-04-14, 23:59 IST
Write a C program to find a ꭍ b x2 dx using Trapezoidal rule with 10 segments between a and b. The values of a and b will be taken from test cases.
#include<stdio.h>
float func(float x);
int main()
{
int n=10; //Taking n=10 sub intervals
float a,b,integral;
scanf("%f",&a);
scanf("%f",&b);
Week-11 Program-03
Due Date of Submission 2022-04-14, 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.
#include <stdio.h>
int checkPrime(int, int);
int main()
{
int num, check;
scanf("%d", &num);
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, int);
int main()
{
int num, check;
scanf("%d", &num);
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;
}
Week-11 Program-04
Due Date of Submission 2022-04-14, 23:59 IST
Write a C program to reverse a word using Recursion. Input to the program is a string that is to be taken from the user and output is reverse of the input word. Note that you have to use recursion.
#include <stdio.h>
#define MAX 100
char *reverse(char[]);
int main()
{
char str[MAX], *rev;
scanf("%s", str);
rev = reverse(str);
printf("The reversed string is : %s\n", rev);
return 0;
}
#define MAX 100
char *reverse(char[]);
int main()
{
char str[MAX], *rev;
scanf("%s", str);
rev = reverse(str);
printf("The reversed string is : %s\n", rev);
return 0;
}