C89 program. Why hasn\'t anyone helped when I posted the question over 8 hours a
ID: 671765 • Letter: C
Question
C89 program. Why hasn't anyone helped when I posted the question over 8 hours ago?
A vector is an ordered collection of values in mathematics. An array is a very straightforward way to implement a vector on a computer. Two vectors are multiplied on an entry-by-entry basis, e.g. (1, 2, 3) * (4, 5, 6) = (4,10,18). Write a program that include the following functions. The functions should use pointer arithmetic (instead of array subscripting). In other words, eliminate the loop index variables and all use of the [] operator in the functions. void multi_vec (int *vl, int *v2, int *v3, int n) ; int comp_vec(int *vl, int *v2, int n); The multi_vec function multiplies vectors vl and v2 and stores the result in v3. n is the length of the vectors. The comp_vec function compares vl and v2, return 1 if vectors vl and v2 are equal (their corresponding components are equal), and 0 otherwise, n is the length of the vectors. In the main function, ask the user to enter the length of the vectors, declare two arrays with the length, read in the values for two vectors, and call the two functions to compute the multiplication and comparison of them. The main function should display the result. Enter the length of the vectors: 5 Enter the firExplanation / Answer
#include <stdio.h>
void multi_vec(int *v1,int *v2,int *v3,int n){
int i=0;
for(i=0;i<n;i++){
*(v3+i)=(*(v2+i))*(*(v1+i));
}
}
int comp_vec(int *v1,int *v2,int n){
int flag=1;
int i=0;
for(i=0;i<n;i++){
if(*(v1+i)!=*(v2+i)){
flag=0;
}
}
return flag;
}
int main() {
int n;
printf("Enter the length of the vectors: ");
scanf("%d",&n);
int v1[n],v2[n];
int i=0;
printf("Enter the first vector: ");
for(i=0;i<n;i++){
scanf("%d",&v1[i]);
}
printf("Enter the second vector: ");
for(i=0;i<n;i++){
scanf("%d",&v2[i]);
}
int v3[n];
multi_vec(v1,v2,v3,n);
printf("The multiplication of the vectors is: ");
for(i=0;i<n;i++){
printf("%d ",v3[i]);
}
if(!comp_vec(v1,v2,n)){
printf(" The vectors are not same ");
}else{
printf(" The vectors are same ");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.