Problem Solving Through Programming In C Week11 Assignment July 2023

Problem-Solving-Through-Programming-In-C-Week11-Assignment-July-2023

NPTEL Problem Solving Through Programming In C Week11 All Programming Assignment Solutions | Swayam July 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!

Problem Solving through Programming In C July 2023

Question : Programming Assignment 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;
}
				
			

Problem Solving through Programming In C July 2023

Question : Programming Assignment 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",integral);
  return 0;
}

float func(float x)
{
  return x*x;
}
				
			

Problem Solving through Programming In C July 2023

Question : Programming Assignment 3  

Problem-Solving-through-programming-in-C-week11-Question3
				
					#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);
    
    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;
}
				
			

Problem Solving through Programming In C July 2023

Question : 4 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.

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