Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help... ARRAYS 1. Choose answers that are applicable for the following qu

ID: 3738859 • Letter: P

Question

Please help...

                                                                            ARRAYS

1.      Choose answers that are applicable for the following questions.

i.            Which of the following is a valid C statement for creating and initializing an array of floating point values?

a.       double densities [ 4.0 ];

b.      int densities [4] = { 1.5, 2.3, 0.1, 4.6 };

c.       double densities [ ] = { 1.5, 2.3, 0.1, 4.6};

d.      int densities [ ];

e.       double densities = { 1.5, 2.3, 0.1, 4.6 };

f.        none of the above

ii.            Which of the following is a valid C code for assigning the same value to each element in an array of floating point values named masses, with a length of 7?

a. int j;

for (j = 0; j <= 7; j++)

{ masses [j] = 2; }

b.      int j;

   for (j = 1; j < 7 ; j++)

                  { masses [j] = 2; }

c. int j;

for (j = 1; j<=7; j++)

{ masses = 2.0; }

d. int j;

for (j = 0; j < 7; j++)

   { masses [j] = 2.0; }

   e. double j;

   for (j =0; j < 7 ; j++)

                  { masses [j] = 2 .0; }

   f. none of the above

iii.             Which of the following is valid C code for summing up all the values in an array of integers named samples, with a length of 7?

a.      int i;

for (i = 0; i < 7 ; i++)

{ samples = samples [i] ; }

b.      int i;

for (i = 1; i <= 7; i++)

{ samples = sum + samples [i]; }

c. int i, sum = 0 ;

for (i = 0; i<7; i++)

{sum = samples[i] + sum; }

d. int i, sum = 0;

for (i = 0; i <= 7; i++)

{ sum = sum + i; }

e. int i, sum;

for (i = 1; i <= 7; i++)

{ sum= samples [i]; }

f.        none of the above

iv.             Which of the following is a valid C statement for creating and initializing an array of character values?

a.       int letters = [ 'p' 'a' 't'];

b.      letters [3] = { p, a, t };

c.    string letters [ ] = { "p", "a", "t" };

   d. letters [3];

e.      char letters [ ] = { 'p', 'a', 't' };

f.        none of the    above

Explanation / Answer

i. Which of the following is a valid C statement for creating and initializing an array of floating point values?

Answer:
b. int densities [4] = { 1.5, 2.3, 0.1, 4.6 };

ii. Which of the following is a valid C code for assigning the same value to each element in an array of floating point values named masses, with a length of 7?
Answer:

e. double j;

for (j =0; j < 7 ; j++)

{ masses [j] = 2 .0; }

iii. Which of the following is valid C code for summing up all the values in an array of integers named samples, with a length of 7?

Answer:

c. int i, sum = 0 ;

for (i = 0; i<7; i++)

{sum = samples[i] + sum; }

iv. Which of the following is a valid C statement for creating and initializing an array of character values?
Answer:

f. none of the above

Size should be mentioned in brackets[]. there is only one char dat type array which does not have size in braces so. option f is right answer.