It seems to me that the problem is more in understanding the problem than in programming. I have not seen any errors in the program, but in what you want to do. Anyway, did you choose one of the most difficult languages to learn? I think it's great how the person starts by C, it means that she will learn the basics, will know what few know. But if you do not have a natural talent for the thing, you'll end up giving up because you have too many problems to solve at hand.
I've said it before and I'll say again that programming is detail. If you do not want to worry about them, actually scheduling will be difficult. Vector is easy. It seems like you're getting into other things.
The problem description does not seem to make sense.
#include <stdio.h>
#define MaxA 2
#define MaxB 3
int main(void) {
int matriza[MaxA], matrizb[MaxB], matrizc[MaxA + MaxB], indice;
for(indice = 0; indice < MaxA; indice++) {
printf("\n digite o valor da matriz A: ");
scanf("%d", &matriza[indice]);
matrizc[indice] = matriza[indice];
}
for(indice = 0; indice < MaxB; indice++) {
printf("\n digite o valor da matriz B: ");
scanf("%d", &matrizb[indice]);
matrizc[indice + MaxA] = matrizb[indice];
}
for(indice = 0; indice < MaxA + MaxB; indice++)
printf("\n Os valores das matrizes A e B sao: %d \n", matrizc[indice]);
return 0;
}
See running on ideone .
I created #define
because the numbers will be used a few times, this way it is easier to change. For example, I did with low numbers so I did not have to be typing a lot, but what the statement asks for is another amount. In your code you use other numbers. Okay, but you know what you're doing?
There are several ways to throw values from the first vectors to the third. The way you choose is smart. But it has to do right. The biggest mistake I saw in the code was that the second vector was being filled all wrong. The code tried to fill in the elements from 8 to 15. But if the vector has only 8 elements of capacity, that is, if they only go from 0 to 7, it is trying to write where it should not. This was because he tried to solve another problem in the wrong way. Solve the loop (note that the problem was not in the vector but in the loop) in the traditional way and solve the vector problem in another way.
So what I did was move the index of the matrizc
vector. I changed this value only. I used the size of matriza
as offset and let the index vary normal.