NPTEL Problem Solving Through Programming In C WEEK 6 Assignment 2023

NPTEL Problem solving through Programming In C Week 6 All Programming Assignment Solutions

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


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
    • 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

Question : 1  Write a C Program to find Largest Element of an Integer Array. 
Here the number of elements in the array ‘n’ and the elements of the array is read from the test data. 
Use the printf statement given below to print the largest element.
printf(“Largest element = %d”, largest);

					#include <stdio.h>
int main()
    int i, n, largest;
    int arr[100];
    scanf("%d", &n); 
    for(i = 0; i< n; ++i)
        scanf("%d", &arr[i]); 
    largest = arr[0];
    for(i = 1; i < n; ++i)
        if(largest < arr[i])
        largest = arr[i];
    printf("Largest element = %d", largest);
    return 0;


Course Name : “Problem Solving through Programming In C

Question : 2  Write a C Program to print the array elements in reverse order (Not reverse sorted order. Just the last element will become first element, second last element will become second element and so on) Here the size of the array, ‘n’ and the array elements is accepted from the test case data. The last part i.e. printing the array is also written. 
You have to complete the program so that it prints in the reverse order.

int main() 
    int arr[20], i, n;
    scanf("%d", &n);
    for(i = 0; i< n; i++) 
        scanf("%d", &arr[i]);
    int j, temp;  
    j = i - 1;   // last Element of the array
    i = 0;       // first element of the array
    while(i < j)
      temp = arr[i];
      arr[i] = arr[j];
      arr[j] = temp;
   for(i = 0; i< n; i++)
        printf("%d\n", arr[i]); // For printing the array elements 

Course Name : “Problem Solving through Programming In C

Question : 3  Write a C program to read Two One Dimensional Arrays of same data type (integer type) and merge them into another One Dimensional Array of same type.

int main() 
    int arr1[20], arr2[20], array_new[40], n1, n2, size, i;
    scanf("%d", &n1); 
    for(i = 0; i< n1; i++)
        scanf("%d", &arr1[i]); 
    scanf("%d", &n2);
    for(i = 0; i< n2; i++)
        scanf("%d", &arr2[i]);
    int j;
    size =  n1 + n2;
    for(i=0, j=n1; j<size && i<n2; ++i, ++j)
        array_new[j] = arr2[i];
    //Printing after merging
    for(i = 0; i< size; i++) 
        printf("%d\n", array_new[i]);

Course Name : “Problem Solving through Programming In C

Question : 4 Write a C Program to delete an element from a specified location of an Array starting from array[0] as the 1st position, array[1] as second position and so on.

int main() {
int array[30], num, i, pos;  
/*num is number of elements in the array and loc is the position of the array to be deleted. 
starting from arr[0] as the first(1) position and so on. */

   scanf("%d", &num); /*Accepts the size of array from test case data */
   for (i = 0; i < num; i++) {
      scanf("%d", &array[i]);  /* Read the array elements from the test case data */
   scanf("%d", &pos);
   while (pos < num)
    array[pos - 1] = array[pos];

  /* Printing the array after deletion */

for (i = 0; i < num; i++)
      printf("%d\n", array[i]);
   return (0);