0
How do I make a program not print vector trash?
For example, I created 2 vectors at the beginning of my program with 5 elements each. If the user type numbers above 10 stores in v1
if it is larger store in v2
. However, when printing, if the user has not entered any number that meets these conditions, the program prints memory junk.
It would be possible to print only the vectors that contain values?
Program for example only:
#include <stdio.h>
#include <stdlib.h>
#define n 5
int main()
{
int v1[n], v2[n], a, i;
for(i=0;i<n;i++)
{
printf("Digite: ");
scanf("%d",&a);
if(a<=5) v1[i] = a;
else v2[i] = a;
}
for(i=0;i<n;i++)
{
printf("%d ", v1[i]);
}
for(i=0;i<n;i++)
{
printf("%d ", v2[i]);
}
system("pause");
return 0;
}
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).
– Maniero