### Introduction to Programming in C Week 8 Answers

#### Week 8: Assignment 8-Question 1

Due on 2022-04-21, 23:59 IST

In this question, you have to write code to remove the first node in a doubly linked list containing a specified number. The code to create the linked list is already given. The main() function calls a function removeData(head,tail,n) to remove the first node containing n from the linked list.

Complete the code by writing the missing function. You can also write additional functions which you may need.

### Solution:

``````#include < stdio.h>
#include < stdlib.h>
{
int data;
};
struct DoublyLinkedList *createNode(int n)
{
newNodeptr->data = n;
newNodeptr->prev = NULL;
newNodeptr->next = NULL;
return newNodeptr;
}
void appendNode ( struct DoublyLinkedList **tailptr, int n )
{
newNode = createNode ( n );
newNode->prev=*tailptr;
(*tailptr)->next = newNode;
*tailptr=newNode;
}
{
newNode=createNode(n);
*tailptr=newNode;
return;
}
{
printf("%d",curr->data);
curr = curr->next;
while (curr != NULL)
{
printf(",%d",curr->data);
curr = curr->next;
}
return;
}
{
int pos = 0;
{
{
return;
}
else
{
return;
}
}
else if((*head)->data != data && (*head)->next == NULL)
{
return;
}
while(curr->next != NULL && curr->data != data)
{
pre_node = curr;
curr = curr->next;
}
if(curr->data == data)
{
pre_node->next = pre_node->next->next;
if(pre_node->next != NULL)
{
pre_node->next->prev = pre_node;
}
else
*tail = pre_node;
free(curr);
}
}
int main()
{
int n;
int i=0;
int m;
scanf("%d",&n);
if ( n < = 0 )
{
return 0;
}
scanf("%d",&m);
for(i=1;i< n;i++)
{
scanf("%d",&m);
appendNode(&tail,m);
}
scanf("%d",&n);
return 0;
}``````

### Week 8:Assignment 8-Question 2

Due on 2022-04-21, 23:59 IST

You are given a non-negative number less than or equal to 100000000 (1 followed by 8 zeroes). You have to divide the number into the following components, and print them in the following order. 1. The part of the number which is less than a thousand. 2. The part of the number which is between a thousand and a lakh 3. The part of the number which is between a lakh and a crore and so on. You should terminate printing when no higher power of 10 is present to be printed.

### Solution: Private Case Passed

``````#include < stdio.h >
int main()
{
int n;
int divisor;
scanf("%d",&n);
divisor=1000;
printf("%d\n",n%divisor);
n=n/divisor;
divisor=100;
while(n!=0)
{
printf("%d\n",n%divisor);
n=n/divisor;
}
}``````