Write a function int set_array(int *v, int i, int j, int k) that sets the elements i to j to a specific value k among the elements of the int array v of size n (<= 100). This is the given problem.
When I input 10 0 9 -1, to set all the elements it comes out normally as -1.
However, when 5 2 2 0 is input, to set only element [2], all output values come out as 0.
I am using eclipse and no error came out. Which part is wrong?
#include <stdio.h>
int set_array(int* v, int i, int j, int k)
{
int t;
for (t = i; t <= j; t++)
{
v[t] = k;
}
return 0;
}
int main()
{
int t;
int size, value;
int start, end;
scanf("%d %d %d %d", &size, &start, &end, &value);
int array[size];
for (t = 0; t < size; t++)
{
scanf("%d", &array[t]);
}
set_array(array, start, end, value);
for (t = 0; t < size; t++)
{
printf("%d\n", array[t]);
}
return 0;
}
int n, i, j, k, t;are for, but we don't. Code is easier to follow when meaningful identifier names are used.[0],[1],[3]and[4], and they happened to be0.