Part 1: Write a C program that declares three 1-D arrays of size n=10, namely A[
ID: 3537704 • Letter: P
Question
Part 1:
Write a C program that declares three 1-D arrays of size n=10, namely A[n], B[n], and
C[n]. Then the program calls a GetArray function that reads real numbers from
keyboard to fill arrays A and B. Then main() calls an add function to add the two arrays
and assign them into a third array. Lastly main() calls a third function such that to print
the resulting function. Then main() will call these three functions in the following
orders:
1- GetArray // To get array A
2- GetArray // To get array B
3- AddArray // To add; C = A + B
4- PrintArray // To print array C
Use the following function prototypes:
void GetArray (float mat[]);
void AddArray (float mat1[],float mat2[], float mat3[]);
void PrintArray (float mat[]);
Part 2:
Write a C program including a main() and a function called checkdiag. main() reads a
square matrix of integer numbers from a file. The file contains an integer number
indicating the identical number of rows and columns followed by the data itself (that
number cannot be larger than 100).
%u2022 For example, a file containing a 3x3 matrix would contain 3 followed by 9
other integer numbers.
Part 3:
Repeat the program from Part 2 by reading from the files into a 1-D array and then
main() calls a search function that finds the minimum and maximum values in the array
and then the function prints the minimum and the maximum to the standard output.
Explanation / Answer
Part(a)
#include <stdio.h>
#include <stdlib.h>
float A[10],B[10],C[10];
void GetArray(float A[])
{
int i=0;
for(i=0;i<10;i++)
{
printf("Enter the number: ");
scanf("%f",&A[i]);
}
}
void AddArray(float A[],float B[],float C[])
{
int i=0;
for(i=0;i<10;i++)
{
C[i]=A[i]+B[i];
}
}
void PrintArray(float C[])
{
int i=0;
for(i=0;i<10;i++)
{
printf("The values are : ",C[i]);
}
}
int main()
{
GetArray(A);
GetArray(B);
AddArray(A,B,C);
PrintArray(C);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.