Write a line of code that declares an array called
uv_levels
that contains 5 integers.
Which element of the array does the following expression refer to?
[3] numbers
4
in each of the
following statements?int numbers[4];
[4] = 25; numbers
double
s, starting at 0 and incrementing by 0.5 for each
value. In other words, the final array should contain
[0.0, 0.5, 1.0, 1.5, 2.0, ..., 4.5]
.#include <stdio.h>
void initialize(_____array, _____length)
{
for (int i = 0; i < length; i++)
{
[_____] = _____;
array}
}
int main(void)
{
// Create the array
[_____];
_____ array
// Initialize array values
(_____, _____);
initialize
// View the values in the array
for (int i = 0; i < 10; i++)
{
("array[%d] = %0.1lf\n", i, array[i]);
printf}
return 0;
}
#include <stdio.h>
void increase_by_one(int array[], int length)
{
for (int i = 0; i < length; i++)
{
[i]++;
array}
}
int main(void)
{
int array[5] = {1, 2, 3, 4, 5};
(array, 5);
increase_by_one
for (int i = 0; i < 5; i++)
{
("%d\n", array[i]);
printf}
return 0;
}
max
, which will be inputted by the user.int main(void)
{
int max;
("Enter the maximum number to go to: ");
printf(_____, _____);
scanf
int size = (max + 1) / 2;
int odd = 1;
int odd_numbers[size];
for (int i = 0; i < _____; i++)
{
[_____] = odd;
odd_numbers= odd + _____;
odd }
for (int i = 0; _____; _____)
{
("%d\n", odd_numbers[_____]);
printf}
return 0;
}
final
array with the squares of the numbers of the
initial
array. That is, if initial
is array of
with elements [1, 2, 3, 4, 5], our program will initialize the
corresponding final
array with the values squared as [1, 4,
9, 16, 25]. Make sure you accept arrays of any size!double square(double num)
{
return num * num;
}
void init_square_array(double *initial, double *final, int count)
{
for (int i = 0; i < _____; _____)
{
[_____] = square(_____);
final}
}
void print_array(double *array, int count)
{
("These are the values of the array!\n");
printffor (int i = _____; i < _____; i++)
{
(_____, array[_____]);
printf}
}
int main(void)
{
double numbers[] = { 1, 2, 3, 4, 5 };
double numbers_results[5];
double evens[10];
double evens_results[10];
double x = 2;
for (int i = 0; i < 10; i++)
{
[i] = x;
evens= x + 2;
x }
(numbers, numbers_results, 5);
init_square_array(evens, evens_results, 10);
init_square_array
(numbers_results, 5);
print_array(evens_results, 10);
print_array
return 0;
}
array1
and array2
, and the length of array1
, that
copies the contents of array1
into array2
.
Assume that array2
has at least as many elements as
array1
.Hint: The function signature will look something like this:
void copy_array(int *array1, int *array2, int length);
#include <stdio.h>
void print_float_array(float *array, int count)
{
for (int i = 0; i < count; i++)
{
(" %f", array[i]);
printf}
("\n");
printf}
int main(void)
{
float values[] = {3.14, 2.718, 6.9, 42.0};
for (int i = 0; i < 4; i++)
{
(values[i], 4);
print_float_array}
return 0;
}
array
) and an integer representing the number of elements
in the array (called length
).