Array Programs
Deletion from array
if (position >= n+1)
#include <stdio.h>
printf("Deletion not possible.\n");
else
int main() {
{ for (c = position - 1; c < n-1 ; c++)
int array[100], position, c, n; array[c] = array[c+1];
printf("Enter number of elements in array\n"); printf("Resultant array:\n");
scanf("%d", &n);
for (c = 0; c < n - 1; c++)
printf("Enter %d elements\n", n); printf("%d\n", array[c]);
}
for (c = 0; c < n; c++)
return 0;
scanf("%d", &array[c]);
}
N=5
printf("Enter the location where you wish to
c=4
delete element\n");
Ar[4]=ar[5]
scanf("%d", &position);
Insertion in array
#include <stdio.h> printf("Enter the value to insert\n");
scanf("%d", &value);
int main()
{ for (c = n - 1; c >= position - 1; c--)
int array[100], position, c, n, value; array[c+1] = array[c];
printf("Enter number of elements in array\n"); array[position-1] = value;
scanf("%d", &n);
printf("Resultant array is\n");
printf("Enter %d elements\n", n);
for (c = 0; c <= n; c++)
for (c = 0; c < n; c++) printf("%d\n", array[c]);
scanf("%d", &array[c]);
return 0;
}
printf("Enter the location where you wish to insert an
element\n"); n=6, pos=3 5, 2
scanf("%d", &position); 13,20
Multiplication matrices
Matrix multiplication
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
mul[i][j]=0;
for(k=0;k<c;k++)
{
mul[i][j]+=a[i][k]*b[k][j];
}
}
}
int main() for (c = 0; c < p; c++)
{ for (d = 0; d < q; d++)
scanf("%d", &second[c][d]);
int m, n, p, q, c, d, k, sum = 0;
int first[10][10], second[10][10], multiply[10][10];
for (c = 0; c < m; c++) {
for (d = 0; d < q; d++) {
printf("Enter number of rows and columns of first matrix\n"); for (k = 0; k < p; k++) {
scanf("%d%d", &m, &n); sum = sum + first[c][k]*second[k][d];
}
printf("Enter elements of first matrix\n");
multiply[c][d] = sum;
for (c = 0; c < m; c++) sum = 0;
for (d = 0; d < n; d++) }
}
scanf("%d", &first[c][d]);
printf("Product of the matrices:\n");
printf("Enter number of rows and columns of second matrix\n");
scanf("%d%d", &p, &q); for (c = 0; c < m; c++) {
for (d = 0; d < q; d++)
printf("%d\t", multiply[c][d]);
if (n != p)
printf("The matrices can't be multiplied with each other.\n"); printf("\n");
else }
{ }
printf("Enter elements of second matrix\n");
return 0;
Transpose matrix
1.#include <stdio.h>
2.
[Link] main()
4.{
5. int m, n, c, d, matrix[10][10], transpose[10][10];
6.
7. printf("Enter the number of rows and columns of matrix\
n");
8. scanf("%d%d", &m, &n);
9.
10. printf("Enter elements of the matrix\n");
11.
12. for (c = 0; c < m; c++)
13. for(d = 0; d < n; d++)
14. scanf("%d", &matrix[c][d]);
15.
16. for (c = 0; c < m; c++)
17. for( d = 0 ; d < n ; d++ )
18. transpose[d][c] = matrix[c][d];
19.
20. printf("Transpose of the matrix:\n");
21.
22. for (c = 0; c < n; c++) {
23. for (d = 0; d < m; d++)
24. printf("%d\t", transpose[c][d]);
25. printf("\n");
26. }
27.
28. return 0;
29.}