1.Write a program that reads in an array of five integers al5] and passes the ar
ID: 3597261 • Letter: 1
Question
1.Write a program that reads in an array of five integers al5] and passes the array to a fiunction largest that returns the value of the largest element in the array. 2.Write a program that reads in two arrays, a|3] and b[3), and passes them to a function Scalarproduct th at returns the scalar product of these arrays; the scalar product of two arrays is 3. Wri te a program that reads in a 2 X 2 square matrix and prints out the determinant of the matrix. a b =a*d-b* c 4. Wri te a program that reads in a 3 X 3 square matrix and prints out the determinant of the matrix. 5. Write a program that solves the following system of equations using Cramer's rule. 5x+7y =-1 6x + 8y = 1 6. Write a program that reads in three matrices A, B and C and calculates the following 1 2 -1 3 1 511 -1 0 3 -20 2 1 a. 2* A+3* B b. C2 c. C.AExplanation / Answer
1)
#include <stdio.h>
int find_max(int[], int);
int main() {
int i, a[100], n,l,m;
printf("Input number of elements in array ");
scanf("%d", &n);
printf("Enter %d integers ", n);
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
l= find_maximum(a, n);
m = a[l];
printf("Maximum element value = %d. ",m);
return 0;
}
int find_maximum(int a[], int s) {
int j, l, pos;
l = a[0];
pos = 0;
for (j = 1; j < s; j++) {
if (a[j] > l) {
pos = j;
l = a[j];
}
}
return pos;
}
ouput:
enter 5 integers
56 9 3 8 5
maximum element value 56
2)))))))))))))))))
#include <stdio.h>
int find_max(int[], int);
int main() {
int i, a[100],b[100], n1,n2,l,m;
printf("Input number of elements in a array ");
scanf("%d", &n1);
printf("Enter %d integers ", n1);
for (i = 0; i < n1; i++)
scanf("%d", &a[i]);
printf("Input number of elements in b array ");
scanf("%d", &n2);
printf("Enter %d integers ", n2);
for (i = 0; i < n2; i++)
scanf("%d", &b[i]);
l= dot_product(a,b,n1);
}
int dot_product(int u[],int v[], int n1)
{
int i,r=0;
for (i = 0; i < n1; i++)
{
r = r+ v[i]*u[i];
}
printf(" scalar product %d",r);
return r;
}
output:
input number of elements in a array
3
enter 3 elements
3 0 0
input number of elements in b array
3
enter 3 elements
5 1 0
scalar product 15
3)))))))))))))
#include <stdio.h>
main()
{
int M[2][2];
int i, j;
long d;
printf("Please Enter matrix elements 2 by 2 size ");
for(i=0; i<2; i++)
{
for(j=0; j<2; j++)
{
scanf("%d", &M[i][j]);
}
}
d = (M[0][0] * M[1][1]) - (M[0][1] * M[1][0]);
printf("Determinant of a matrix M = %ld", d);
}
output:
Please Enter matrix elements 2 by 2 size
Determinant of a matrix M = -12
4)))))))))))))
#include <stdio.h>
int main()
{
int M[3][3];
int i, j;
int p, q, r, s, t, u, v, w, x;
long d;
printf("Enter elements in matrix of size 3x3: ");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
scanf("%d", &M[i][j]);
}
}
p = M[0][0];
q = M[0][1];
r = M[0][2];
s = M[1][0];
t = M[1][1];
u = M[1][2];
v = M[2][0];
w = M[2][1];
x = M[2][2];
d = (p*(t*x - u*w)) - (q*(s*x - u*v)) + (r*(s*w - t*v));
printf("Determinant for the matrix M = %ld", d);
return 0;
}
output:
Enter elements on matrix of size 3*3
3 5 6 0 4 8 4 0 2
determinant for the matrix M = 88
4 6 8 9
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.