NPTEL 2 min read Updated Sep 2023

NPTEL Problem Solving Through Programming In C WEEK 12 Assignment 2023

Faheem Ahmad

2 reads

NPTEL Problem Solving Through Programming In C WEEK 12 Assignment

NPTEL Problem solving through Programming In C Week 12 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  Write a program in C to find the factorial of a given number using pointers.

C
#include <stdio.h>
void findFact(int, long int*);
int main()
{
        long int fact; //factorial of the number
        int num1; 
		scanf("%d",&num1); //The number is taken from test data

         findFact(num1, &fact);
         printf("The Factorial of %d is : %ld\n",num1, fact);
         return 0;
}

void findFact(int n, long int *f)
{
	int i;
	*f =1;
  	for(i=1;i<=n;i++)
    	*f=*f*i;
}

Course Name : “Problem Solving through Programming In C 2023”

Program : 2  Write a C program to print the Record of the Student Merit wise. Here a structure variable is defined which contains student rollno, name and score.

C
#include<stdio.h>
struct student
{
    int rollno;
    char name[20];
    int score;
};
void main()
{
    struct student s[20];
    int i, n;
    
    scanf("%d" ,&n); //No. of Students taken from test data
    // Roll no., Name and Score of n students are taken from test data
    for(i=0;i<n;i++)
    {
        scanf("%d", &s[i].rollno);
        scanf("%s", s[i].name);
        scanf("%d", &s[i].score);
    }
    
    //Complete the program so that merit list is printed in descending order
    struct student temp;
    int j;
    for(i=0;i<n-1;i++)
    {
      for(j=0;j<n-1;j++)
      {
        if(s[j].score<s[j+1].score)
        {
          temp=s[j];
          s[j]=s[j+1];
          s[j+1]=temp;
        }
      }
    }
    printf("The Merit List is :\n");
    for(i=0;i<n;i++)
    {
        printf("%d", s[i].rollno);
        printf("  %s", s[i].name);
        printf("  %d\n", s[i].score);
    }

}

Course Name : “Problem Solving through Programming In C 2023”

Program : 3  Write a C program to store n elements using Dynamic Memory Allocation – calloc() and find the Largest element

C
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n; 
    float *element;

    scanf("%d", &n);
    element = (float*) calloc(n, sizeof(float));

    if(element == NULL)
    {
        printf("Error!!! memory not allocated.");
        exit(0);
    }

    // Stores the number entered by the user.
    int i;
    for(i = 0; i < n; ++i)
    {
        scanf("%f", element + i);
    }

 	// find the largest
    for(i = 1; i < n; ++i)
    {
       if(*element < *(element + i))
         *element = *(element + i);
    }
    printf("Largest element = %.2f\n", *element);
    return 0;
}

Course Name : “Problem Solving through Programming In C 2023”

Program : 4 Write a C program to add two distance given as input in feet and inches.

C
#include<stdio.h>

struct Distance{
    int feet;
    int inch;
}d1,d2,sum;

int main()
    {
    //Enter 1st distance
    scanf("%d",&d1.feet); 
    scanf("%d",&d1.inch);
    //Enter 2nd distance
    scanf("%d",&d2.feet);
    scanf("%d",&d2.inch);
    sum.feet=d1.feet+d2.feet;
    sum.inch=d1.inch+d2.inch;
 
	/* If inch is greater than 12, converting it to feet. */
    if (sum.inch>=12)
    {
        sum.inch=sum.inch-12;
        ++sum.feet;
    }
    printf("Sum of distances = %d feet %d inches",sum.feet,sum.inch);
    return 0;
}

// written by

Faheem Ahmad

Writer at Techies Talk

Faheem writes about NPTEL, Coursera, and How To on Techies Talk, turning tricky topics into guides you can follow step by step.

Writes about #NPTEL117 #Coursera13 #How To5

Articles
145
Reads
320
Writing since
2020
All posts by Faheem