Professional Documents
Culture Documents
Program 1
Source Code
#include <stdio.h>
#include <stdlib.h>
int data;
}node;
node* getnode();
//main method
int main()
int n, i=0;
do{
scanf("%d",&n);
if(n<=0)
Page 1
Set No: 2
}while(n<=0);
while(i<n)
if(i==0)
head = getnode();
q=head;
i=i+1;
else
x=getnode();
q->next=x;
q=q->next;
i=i+1;
displayList(head);
return 0;
Page 2
Set No: 2
node* getnode()
int item;
scanf("%d",&item);
new->data = item;
new->next = NULL;
return new;
node *temp;
if (head == NULL)
printf("List is empty.\n");
temp = head;
temp = temp->next;
Page 3
Set No: 2
Output
Page 4
Set No: 2
Program 2
Source Code
#include <stdio.h>
#include <stdlib.h>
//main method
int main()
{
float *arr;
int pos, i, n;
//Taking the value of n from the user
printf("Enter number of elements in array\n");
scanf("%d", &n);
//Creating the array dynamically
arr = calloc(n, sizeof(float));
//Entering the elements into the array
printf("Enter the %d elements\n", n);
for (i = 0; i < n; i++)
scanf("%f", &arr[i]);
// Entering the deleting location
printf("Enter the location where you wish to delete element\n");
scanf("%d", &pos);
//Deletion operation
if (pos <=0||pos >= n+1 )
printf("Deletion not possible.\n");
else
{
for (i = pos-1; i<n-1; i++)
arr[i] = arr[i+1];
}
//Displaying the resultant array after deletion
printf("Resultant array:\n");
for (i = 0; i < n - 1; i++)
printf("%f ", arr[i]);
return 0;
}
Page 5
Set No: 2
Output
Page 6
Set No: 2
Program 3
Source Code
Output
Page 7
Set No: 2
Program 4
Source Code
Output
Page 8