NPTEL Problem Solving Through Programming In C WEEK 10 Assignment July 2022

Problem-solving-through-Programming-In-C-Week10-Programming-Assignment-Solutions

NPTEL Problem solving through Programming In C Week 10 All Programming Assignment Solutions | Swayam 2022. 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 2022

Program : 1  

Problem-Solving-through-programming-in-C-week10-Question1
				
					#include<stdio.h>
float fun (float x); 
void bisection (float *x, float a, float b, int *itr);

int main ()
{
    int itr = 0, maxmitr=10;
    float x, a=1.0, b=2.0, allerr, x1; 
   

    scanf("%f", &allerr);
    bisection (&x, a, b, &itr);
    do
    {
        if (fun(a)*fun(x) < 0)
            b=x;
        else
            a=x;
        bisection (&x1, a, b, &itr);
        if (((x1-x)<0 && -(x1-x)< allerr) || ((x1-x)>0 && (x1-x)< allerr))
        {
            printf("Root = %1.4f\n", x1);
            return 0;
        }
        x=x1;
    }
    while (itr < maxmitr);
    return 1;
}

float fun(float x)
{
    return (2*x*x*x - 3*x - 5);
}

void bisection(float *x, float a, float b, int *itr)
/* this function performs and prints the result of one iteration */
{
    *x=(a+b)/2;
    ++(*itr);
}

				
			

Course Name : “Problem Solving through Programming In C 2022

Program : 2  

Problem-Solving-through-programming-in-C-week10-Question2
				
					#include<stdio.h>
float f(float x);
float df (float x);

int main()
{
    int itr, maxmitr; 
    float x0=1.0, x1;
    scanf("%d", &maxmitr);
    float h;
    for (itr=1; itr<=maxmitr; itr++)
    {
        h=f(x0)/df(x0);
        x1=x0-h;
        x0=x1;
    }
    printf("Root = %8.6f\n", x1);
    return 0;
}

float f(float x)
{
    return x*x*x - 2*x  - 3;
}

float df (float x)
{
    return 3*x*x-2;
}
				
			

Course Name : “Problem Solving through Programming In C 2022

Program : 3  Write a C program to sort a given 1D array using pointer in ascending order.

				
					#include <stdio.h>
int main()
{
    int a[100],i, n;
    scanf("%d",&n);
    for (i=0; i<n; i++)
    {
        scanf("%d",a+i);
    }
    int j,t;
	for(i=0; i<(n-1); i++) 
    {
        for (j=i+1; j<n; j++)
        {
            if (*(a+i)>*(a+j))
            {
                t=*(a+i);
                *(a+i)=*(a+j);
                *(a+j)=t;
            }
        }
    }
    
    for (i=0; i<n; i++)
    {
        printf("%d\n",*(a+i));
    }
    return 0;
}


				
			

Course Name : “Problem Solving through Programming In C 2022

Program : 4  Write a C code to check if a 3 x 3 matrix is invertible. A matrix is not invertible if its determinant is 0.

				
					#include<stdio.h>
int main()
{
  int a[3][3], i, j;
  long determinant;
  for(i = 0 ; i < 3; i++)
      for(j = 0; j < 3; j++)
           scanf("%d", &a[i][j]);
  determinant = a[0][0] * ((a[1][1]*a[2][2]) - (a[2][1]*a[1][2])) -a[0][1] * (a[1][0]
   * a[2][2] - a[2][0] * a[1][2]) + a[0][2] * (a[1][0] * a[2][1] - a[2][0] * a[1][1]);
  if ( determinant == 0)
       printf("The given matrix is not invertible");
  else
       printf("The given matrix is invertible");
  return 0;
}