Ok
so I tried to follow what the link you sent me was describing. I still
don't really get how to do this. the specifications say the program
should take in the vector values as such:
Size of the vector: 3
Vector value: 2 2 1
size of the vector is the 'n' input that i would pass in to
read_vector()
so i'm thinking of something like this...
Code:
void read_vector(int *v, int n)
{
int i = 0,
value = 0;
printf("Vector value: ");
while (getchar() != '\n')
{
scanf("%d", &value); v[i] = value;
}
}
but for some reason i still get an error... what's interesting is that it won't even get to the printf statement at the beggining....maybe its something from the previous function where the porblem lies???
this one:
Code:
void addition(void)
{
int n1, n2;
printf(" Size of the first vector: "); // vector 1
scanf("%d", n1);
int vector_1[n1];
read_vector(vector_1, n1);
printf(" Size of the second vector: "); // vector 2
scanf("%d", n2);
int vector_2[n2];
read_vector(vector_2, n2);
int nres = (n1 >= n2 ? n1: n2);
int result[nres];
if ( vector_addition(vector_1, n1, vector_2, n2, result) == true)
print_vector(result, nres);
else printf("Error: vectors must be equal in size. Addition undefined.");
}
i don't know what the hell is going on really.... haha.. I'm learning sorry.
this is what I get in the prompt:
~/Desktop/P5 $./a.out
Code:
main menu:
1. Vector..Addition
2. Scalar..Multiplication
3. Dot..Product
4. Outer..Product
5. Matrix..Addition
6. Matrix..Multiplication
7. Quit
Enter your selection[1..7]: 1
Size of the first vector: 3
Bus error