Cpro
Cpro
/*output
Enter size of elements:5
Enter numbers:1 7 8 9 6
Sorted list in ascending order:
1 6 7 8 9 */
//program to add two matrices
#include<stdio.h>
void main()
{
int a[10][10],b[10][10],r,c,s[10][10],i,j;
printf("Enter rows of the matrices:");
scanf("%d",&r);
printf("Enter columns of the matrices:");
scanf("%d",&c);
printf("Enter elements of the first matrix:\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
scanf("%d",&a[i][j]);
}
printf("Enter elements of the second matrix:\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
scanf("%d",&b[i][j]);
}
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
s[i][j]=(a[i][j]+b[i][j]);
}
}
printf("The sum of two matrices is \n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
printf("%d\t",s[i][j]);
printf("\n");
}
}
/*output
Enter rows of the matrices:3
Enter columns of the matrices:3
Enter elements of the first matrix:
258
147
369
Enter elements of the second matrix:
123
456
789
The sum of two matrices is
3 7 11
5 9 13
10 14 18
//program to read n integers, store them in an array and
//search for an element in the array using linear search
#include <stdio.h>
void main()
{
int a[20],s,i,n;
printf("Enter the limit of array\n");
scanf("%d",&n);
printf("Enter numbers of your array\n",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter the number to search\n");
scanf("%d",&s);
for(i=0;i<n;i++)
{
if(a[i]==s)
{
printf("%d is present \n",s);
break;
}
}
if(i==n)
printf("%d is not present \n",s);
}
/*output
Enter the limit of array
15
Enter numbers of your choice
11 13 15 17 19
Enter the number to search
15
15 is present */
/*program to multiply two matrix*/
#include<stdio.h>
void main()
{
int a[10][10],b[10][10],r1,c1,r2,c2,i,j,k,s[10][10];
printf("Enter rows of first matrix:");
scanf("%d",&r1);
printf("Enter columns of first matrix:");
scanf("%d",&c1);
printf("Enter rows of second matrix:");
scanf("%d",&r2);
printf("Enter columns of second matrix:");
scanf("%d",&c2);
printf("Enter the elements of the first matrix: \n");
if(r2==c1)
{
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
scanf("%d",&a[i][j]);
}
printf("Enter the elements of the second matrix: \n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
scanf("%d",&b[i][j]);
}
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
s[i][j]=1;
for(k=0;k<c2;k++)
s[i][j]=(a[i][k]*b[k][j]);
}
}
printf("The multiplication of two matrices will give \n");
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
printf("%d\t",s[i][j]);
}
printf("\n");
}
}
else
printf("It cannot be multiplied");
}
//output
Enter rows of first matrix:3
Enter columns of first matrix:3
Enter rows of second matrix:3
Enter columns of second matrix:3
Enter the elements of the first matrix:
368
569
423
Enter the elements of the second matrix:
785
456
235
The multiplication of two matrices will give
16 24 40
18 27 45
6 9 15
//program to find the transpose of a matrix
#include<stdio.h>
void main()
{
int a[10][10],b[10][10],i,j,r,c;
printf("Enter the rows of the matrix:");
scanf("%d",&r);
printf("Enter the columns of the matrix:");
scanf("%d",&c);
printf("Enter the elements of the matrix:\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
scanf("%d",&a[i][j]);
}
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
b[i][j]=a[j][i];
}
//*output
Enter the rows of the matrix:3
Enter the columns of the matrix:3
Enter the elements of the matrix:
748
965
152
The transpose of a matrix is
7 9 1
4 6 5
8 5 2
*/