NPTEL Problem Solving Through Programming In C WEEK 11 Assignment 2023

NPTEL Problem solving through Programming In C Week 11 All Programming Assignment Solutions | Swayam 2023. With the growth of Information and Communication Technology, there is a need to develop large and complex software.

ABOUT THE COURSE:

This course is aimed at enabling the students to:
  • Formulate simple algorithms for arithmetic and logical problems
  • Translate the algorithms to programs (in C language)
  • Test and execute the programs and  correct syntax and logical errors
  • Implement conditional branching, iteration and recursion
  • Decompose a problem into functions and synthesize a complete program using divide and conquer approach
  • Use arrays, pointers and structures to formulate algorithms and programs
  • Apply programming to solve matrix addition and multiplication problems and searching and sorting problems 
  • Apply programming to solve simple numerical method problems, namely rot finding of function, differentiation of function and simple integration
COURSE LAYOUT
    • Week 1 : Introduction to Problem Solving through programs, Flowcharts/Pseudo codes, the compilation process, Syntax and Semantic errors, Variables and Data Types
    • Week 2 : Arithmetic expressions, Relational Operations, Logical expressions; Introduction to Conditional Branching
    • Week 3 : Conditional Branching and Iterative Loops
    • Week 4 : Arranging things : Arrays
    • Week 5 : 2-D arrays, Character Arrays and Strings 
    • Week 6 : Basic Algorithms including Numerical Algorithms
    • Week 7 : Functions and Parameter Passing by Value
    • Week 8 : Passing Arrays to Functions, Call by Reference
    • Week 9 : Recursion
    • Week 10 : Structures and Pointers
    • Week 11 : Self-Referential Structures and Introduction to Lists
    • Week 12 : Advanced Topics

Once again, thanks for your interest in our online courses and certification. Happy learning!

Course Name : “Problem Solving through Programming In C 2023

Program : 1  

Week11-Programming-Assignment1
				
					#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);
  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;
}
				
			

Course Name : “Problem Solving through Programming In C 2023

Program : 2  

W11-Program2
				
					#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);
  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;
}


				
			

Course Name : “Problem Solving through Programming In C 2023

Program : 3

Problem-Solving-through-programming-in-C-week11-Question3
				
					#include<stdio.h>
float func(float x,float y);
int main()
{
    float xn; 
    scanf("%f", &xn);
    float g1,g2,g3,g4,g,h=0.3;
    float x0 = 0.3, y0 = 5;
    while(x0 < xn)
    {
        g1=func(x0,y0);
        g2=func((x0+h/2.0),(y0+g1*h/2));
        g3=func((x0+h/2.0),(y0+g2*h/2));
        g4=func((x0+h),(y0+g3*h));
        g=((g1+2*g2+2*g3+g4)/6);
        y0=y0+g*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;
} 
				
			

Course Name : “Problem Solving through Programming In C 2023

Program : 4 

W11-Program3
				
					#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);
    }
}