Professional Documents
Culture Documents
AIM:
To write a program to find sum of elements in arrays, to insert an element in an array, to delete an
element in an array and to reverse the elements in the single dimension array.
ALGORITHM:
• Start the program.
• Declare the variable as array.
• Initialise the value of the sum = 0.
• Get the array elements.
• Find the sum of the array using the looping structure. Sum = sum+a[i]
• Print the sum of the elements.
• Get the position of term which is to inserted.
• Make an additional cell and place the term as a[i+1]=a[i] until the iteration of i=n. And at the
term a[n] get the value of the element to be inserted and placed in a[n].
• Print the array.
• Get the position of term to be deleted.
• By placing the term a[i-1]=a[i] until the iteration of the i=n.
• Print the array.
• Declare a new array.
• By looping statement reverse the array as follows.(initialise i=0; j=n)
● a[i] = b[j]
● ++i● --j
• Print the reversed array.
PROGRAM:
#include<stdi
o.h> int
main()
scanf("%d",&a[i]);
for(i=0;i<n;++i)
x[i]=a[i];
printf("%d\t",a[i]);
for(i=0;i<n;++i)
c=c+a[i];
printf("\nEnter the position a[n] in which the new number to be inserted: n= "); scanf("%d",&j);
for(i=n;i>=j;--i)
a[i+1]=a[i];
}
a
[j
]
=
k
;
printf("%d\t",a[i]);
}
printf("
\n");
for(i=0;i<n;++i)
a[i]=x[i];
printf("\nEnter the position a[n] in which the number to be deleted: n= "); scanf("%d",&j);
for(i=j;i<n;++i)
a[i]=a[i+1];
printf("%d\t",a[i]);
for(i=0;i<=n;++i)
b[n-i-1]=x[i];
printf("%d\t",b[i]);
printf("\n");
OUTPUT:
RESULT:
Thus the given operations are performed in a single dimensional array.
Ex. No:5(B)
DATE: PROGRAM TO MULTIPLY TWO MATRICES.
19/02/2021
AIM:
To write a program to multiply two matrices using c program.
ALGORITHM:
• Start the Program.
FLOWCHART:
PROGRAM:
#include <stdio.h>
i
n
t
m
a
i
n
(
)
{
int m, n, p, q, c, d, k, sum = 0;
int first[10][10], second[10][10], multiply[10][10];
printf("Enter the number of rows and columns of first
matrix\n"); scanf("%d%d", &m, &n);
printf("Enter the elements of first
matrix\n"); for (c=0;c<m;c++)
for (d=0;d<n;d++) scanf("%d",
&first[c][d]);
printf("Enter the number of rows and columns of second matrix\n");
scanf("%d%d", &p, &q);
if ( n != p )
printf("Matrices with entered orders can't be multiplied with each
other.\n"); else
{
printf("Enter the elements of second
matrix\n"); for ( c=0;c<p;c++ )
for (d=0;d<q;d++) scanf("%d",
&second[c][d]);
for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < q ; d++ )
{
for ( k = 0 ; k < p ; k++ )
{
sum = sum + first[c][k]*second[k][d];
}
multiply[c][d] = sum;
sum = 0;
}
}
printf("Product of entered matrices:-\n");
for ( c = 0 ; c < m ; c++ )
{
for ( d = 0 ; d < q ; d++ )
printf("%d\t", multiply[c][d]);
printf("\n");
}
r
e
t
u
r
n
0
;
OUTPUT:
RESULT:
Thus the program to multiply two matrices are coded the two matrix A and B are multiplied
and the result matrices is printed.