NPTEL » Introduction to programming in C
Jan 2023 NPTEL course
Scroll Down for latest Assignments
Support me : Subscribe to the YouTube Channel : Swayam Solver
Week 1: Assignment 1 - Question 1
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 5 1 2 120
| 1 | 1 | Passed |
Test Case 2 | 3 17 9 500
| 0 | 0 | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Test Case 2 | Passed |
Test Case 3 | Passed |
Test Case 4 | Passed |
Test Case 5 | Passed |
Week 1: Assignment 1 - Question 2
Check whether M is an exact multiple of N, without using loops.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 10 5 | 1 | 1 | Passed |
Test Case 2 | 10 7 | 0 | 0 | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Test Case 2 | Passed |
Test Case 3 | Passed |
Test Case 4 | Passed |
Test Case 5 | Passed |
Week 1: Assignment 1 - Question 3
Input
-------
Triplet of three integers (a,b,c)
Output
---------
You have to output 1 if they are either in strictly increasing (a>b>c) or decreasing (a<b<c) order.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 4 3 2 | 1 | 1 | Passed |
Test Case 2 | 1 2 1 | 0 | 0 | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Test Case 2 | Passed |
Test Case 3 | Passed |
Test Case 4 | Passed |
Test Case 5 | Passed |
-----------------------------------------------------------
Week 2: Assignment 2 - Question 1
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 1 2 4 3 5 -1 | 4 | 4 | Passed |
Test Case 2 | 5 5 5 -1 | 0 | 0 | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Test Case 2 | Passed |
Test Case 3 | Passed |
Test Case 4 | Passed |
Test Case 5 | Passed |
Week 2: Assignment 2 - Question 2
That is if the sequence is then for all i from 1 to n-1.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 1 2 3 -1 | 3 | 3 | Passed |
Test Case 2 | 1 1 2 -1 | 2 | 2 | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Test Case 2 | Passed |
Test Case 3 | Passed |
Test Case 4 | Passed |
Test Case 5 | Passed |
Week 2: Assignment 2 - Question 3
You have to determine whether the matrix is an upper triangular matrix.
Note: The diagonal itself, and the entries above the diagonal can be zeroes or non-zero integers.
-------
---------
If the input matrix is upper triangular, then print 1. Otherwise, print 0.
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 3
1 1 1
0 1 1
0 0 1
| 1 | 1 | Passed |
Test Case 2 | 4
1 0 3 4
5 6 7 0
0 9 3 2
1 1 1 0 | 0 | 0 | Passed |
Test Case 3 | 3
1 1 1
0 0 1
0 0 1 | 1 | 1 | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Test Case 2 | Passed |
Test Case 3 | Passed |
Test Case 4 | Passed |
Test Case 5 | Passed |
Week 3: Assignment 3 - Question 1
The factorial of a positive integer , denoted by , is the product of all positive integers less than or equal to .
---------
The first line of input is a positive integer N.
The next line contains N positive integers for .
Output
---------
For each given as input, print factorial of .
Note
---------
The code stub given takes care of reading the input, passing it over to the function find_factorial and printing the value (factorial of k) returned by the function. You have to just complete the function find_factorial, which takes a single positive integer as input and returns .
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 3
1 3 6 | 1 6 720 | 1 6 720 | Passed after ignoring Presentation Error |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Test Case 2 | Passed |
Week 3: Assignment 3 - Question 2
Input
--------
- The first line contains a positive integer k.
- In the second line, you will be given a sequence of numbers terminated with a -1.
----------
------------------
--------------------
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 2
1 4 3 6 5 4 1 -1 | 3 | 3 | Passed |
Test Case 2 | 3
2 4 1 9 4 4 -1 | -1 | -1 | Passed |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Test Case 2 | Passed |
Test Case 3 | Passed |
Week 3: Assignment 3 - Question 3
The two moving average is the sequence of averages of the last 2 entries.
For the first number, no average is output.
The -1 is not part of the sequence. There will be at least 3 numbers in the sequence.
Output
Public Test Cases | Input | Expected Output | Actual Output | Status |
---|---|---|---|---|
Test Case 1 | 1 3 2 4 -1 | 2.0 2.5 3.0 | 2.0 2.5 3.0 | Passed after ignoring Presentation Error |
Private Test cases used for Evaluation | Status |
Test Case 1 | Passed |
Test Case 2 | Passed |
Test Case 3 | Passed |
Test Case 4 | Passed |
#include <stdio.h>
#include <stdlib.h>
struct DoublyLinkedList {
int data;
struct DoublyLinkedList * prev;
struct DoublyLinkedList * next;
};
/*
--------------------------
Create a new node
--------------------------
*/
struct DoublyLinkedList * createNode(int n) {
struct DoublyLinkedList * newNodeptr;
newNodeptr = (struct DoublyLinkedList * )
malloc(sizeof(struct DoublyLinkedList));
newNodeptr -> data = n;
newNodeptr -> prev = NULL;
newNodeptr -> next = NULL;
return newNodeptr;
}
/*
--------------------------------
add a node at the end of a doubly linked list.
Tailptr is the address of the pointer to the end of the current list.
After adding the node, tail points to the new node inserted.
--------------------------------
*/
void appendNode(struct DoublyLinkedList ** tailptr, int n) {
struct DoublyLinkedList * newNode;
newNode = createNode(n);
newNode -> prev = * tailptr;
( * tailptr) -> next = newNode;
* tailptr = newNode;
}
void initializeList(
struct DoublyLinkedList ** headptr,
struct DoublyLinkedList ** tailptr,
int n) {
struct DoublyLinkedList * newNode;
newNode = createNode(n);
* headptr = newNode;
* tailptr = newNode;
return;
}
void printList(
struct DoublyLinkedList * head,
struct DoublyLinkedList * tail) {
struct DoublyLinkedList * curr = head;
while (curr != NULL) {
if (curr -> next != NULL)
printf("%d,", curr -> data);
else printf("%d", curr -> data);
curr = curr -> next;
}
return;
}
/* additional functions used */
struct DoublyLinkedList * search(struct DoublyLinkedList * list, int id) {
struct DoublyLinkedList *curr=list;
while(curr!=NULL && curr->data!=id)
curr=curr->next;
return curr;
}
/*
COMPLETE THE FUNCTION GIVEN BELOW
--------------------------------
remove the node contains data with value n.
After removing the first node, we should reset head.
After removing the last node, we should reset tail.
--------------------------------
*/
void removeData(
struct DoublyLinkedList * headptr,
struct DoublyLinkedList * tailptr,
int n) {
struct DoublyLinkedList * e = search(headptr, n);
if (e != NULL)
{
if(e->prev==headptr)
headptr=e->next;
if(e->next==tailptr)
tailptr=e->prev;
e->next->prev=e->prev;
e->prev->next=e->next;
}
free(e);
}
int main() {
int n;
int i = 0;
int m;
struct DoublyLinkedList * head, * tail;
scanf("%d", & n);
if (n <= 0) {
return 0;
}
scanf("%d", & m);
initializeList( & head, & tail, m);
for (i = 1; i < n; i++) {
/* read the remaining elements */
scanf("%d", & m);
appendNode( & tail, m);
}
scanf("%d", & n);
removeData( head, tail, n);
printList(head, tail);
return 0;
}
thank you sir
ReplyDeletethank you so much for helped me to save time
ReplyDelete