1write A Program To Find The Mean and The Median of The Numbers Stored in An Array
1write A Program To Find The Mean and The Median of The Numbers Stored in An Array
#include <stdio.h>
#include <stdlib.h>
int sum = 0;
sum += a[i];
if (n % 2 != 0)
int main()
int a[] = { 1, 3, 4, 2, 7, 5, 8, 6 };
// Function call
return 0;
}
Q2 Write a program to insert one element in an array and delete an element from an array.
#include <stdio.h>
int main() {
int array[MAX_SIZE];
scanf("%d", &n);
scanf("%d", &array[i]);
scanf("%d", &pos);
switch (pos) {
case 1:
array[i + 1] = array[i];
scanf("%d", &value);
// Assign the value to the specified position
array[0] = value;
n++;
break;
case 2:
scanf("%d", &value);
array[n] = value;
n++;
break;
default:
array[i + 1] = array[i];
}
scanf("%d", &value);
array[pos - 1] = value;
n++;
} else {
printf("Invalid position.\n");
break;
scanf("%d", &pos);
switch (pos) {
case 1:
n--;
break;
case 2:
n--;
break;
default:
n--;
} else {
printf("Invalid position.\n");
}
break;
return 0;
}
Q3 write a program to search for a number in an array.
int main()
scanf("%d",&n);
scanf("%d", &arr[i]);
scanf("%d", &search);
if (arr[i] == search)
break;
if (i == n)
return 0;
}
Q4 Write a program to sort an array
#include <stdio.h>
*xp = *yp;
*yp = temp;
int i, j, min_idx;
// unsorted subarray
// unsorted array
min_idx = i;
min_idx = j;
swap(&arr[min_idx], &arr[i]);
}
}
int i;
printf("\n");
// Driver code
int main()
printArray(arr, n);
selectionSort(arr, n);
printArray(arr, n);
return 0;
}
Q5 Write a program to merge two sorted arrays
#include <stdio.h>
int main()
scanf("%d",&n1);
scanf("%d", &a[i]);
scanf("%d",&n2);
scanf("%d", &b[i]);
n3 = n1 + n2;
c[i] = a[i];
int temp;
c[i] = c[j];
c[j] = temp;
printf(" %d ",c[i]);
return 0;
#include <stdio.h>
int main()
int arr[10][5];
int a;
for(int i=0;i<10;i++)
for(int j=0;j<5;j++)
scanf("%d",&arr[i][j]);
}
}
#include <stdio.h>
#include <stdlib.h>
struct node{
int data;
};
int main()
head->data=15;
head->next=first;
first->data=14;
first->next=second;
second->data=13;
second->next=NULL;
while(ptr!=NULL)
printf("%d \n",ptr->data);
ptr=ptr->next;
Q8 Write a program to insert a node in a linked list and delete a node from a linked list
#include <stdio.h>
#include <stdlib.h>
struct node{
int data;
};
int main()
head->data=15;
head->next=first;
first->data=14;
first->next=second;
second->data=13;
second->next=NULL;
struct node* p;
int a;
scanf("%d",&a);
p->data=head->data;
p->next=head->next;
head->data=a;
head->next=p;
ptr=head;
while(ptr!=NULL)
printf("%d \n",ptr->data);
ptr=ptr->next;
d=head;
head->data=p->data;
head->next=p->next;
pt=head;
while(pt!=NULL)
printf("%d \n",pt->data);
pt=pt->next;
Q9 Write a program to print the element sofa linked list in reverse order
#include <stdio.h>
#include <stdlib.h>
struct node{
int data;
};
int main()
head->data=15;
head->next=first;
head->prev=NULL;
first->data=14;
first->next=second;
first->prev=head;
second->data=13;
second->next=NULL;
second->prev=first;
struct node* a;
a=head;
while(a!=NULL)
printf("%d \n",a->data);
a=a->next;
struct node* d;
d=second;
while(d!=NULL)
printf("%d \n",d->data);
d=d->prev;
#include <stdio.h>
#include <stdlib.h>
struct node{
int data;
};
int main()
int arr[3];
head->data=15;
head->next=first;
head->prev=NULL;
first->data=14;
first->next=second;
first->prev=head;
second->data=13;
second->next=NULL;
second->prev=first;
ptr=head;
printf("%d \n",ptr->data);
arr[i]=ptr->data;
ptr=ptr->next;
ptr=head;
for(int i=2;i>=0;i--)
ptr->data=arr[i];
printf("%d \n",ptr->data);
ptr=ptr->next;
#include <stdio.h>
#include <stdlib.h>
struct Node {
int coef;
int exp;
};
temp->coef = coef;
temp->exp = exp;
temp->next = NULL;
if (*poly == NULL) {
*poly = temp;
return;
current = current->next;
current->next = temp;
if (poly == NULL) {
printf("0\n");
return;
if (current->next != NULL) {
printf(" + ");
current = current->next;
printf("\n");
}
Node* add(Node* poly1, Node* poly2) {
if (poly1->exp == poly2->exp) {
poly1 = poly1->next;
poly2 = poly2->next;
poly1 = poly1->next;
} else {
poly2 = poly2->next;
poly1 = poly1->next;
poly2 = poly2->next;
return result;
int main() {
insert(&poly1, 3, 2);
insert(&poly1, 1, 0);
insert(&poly2, 4, 4);
insert(&poly2, 2, 2);
insert(&poly2, 1, 1);
print(poly1);
print(poly2);
printf("Result: ");
print(result);
return 0;