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

2- a program that creates an integer array of length 30, fills the array with th

ID: 664869 • Letter: 2

Question

2- a program that creates an integer array of length 30, fills the array with the sequence of values (shown below) using a for loop, and then loops through the array printing out the values. Use a for-each style for loop to print out the values. (Recreate the array for each set A,B,C,D and print it all in the same program) 1, 3, 5, -6, 29, -30 1, 1, 2, 2, 3, 3 15, 15 1, 2, 4, 8, 16, 1, 1, 2, 3, 5, 8, 13, Except for the first two values, each value is the sum of the two preceding values) a ust ba recu

Explanation / Answer

#include <stdio.h>

void oneWay(void);

void anotherWay(void);

int main(void) {

   printf(" oneWay: ");

   oneWay();

   printf(" antherWay: ");

   anotherWay();

}

/*Array initialized with aggregate */

void oneWay(void) {

   int vect[10] = {1,2,3,4,5,6,7,8,9,0};

   int i;

   for (i=0; i<10; i++){

       printf("i = %2d vect[i] = %2d ", i, vect[i]);

   }

}

/*Array initialized with loop */

void anotherWay(void) {

   int vect[10];

   int i;

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

        vect[i] = i+1;

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

        printf("i = %2d vect[i] = %2d ", i, vect[i]);

}

/* The output of this program is

   oneWay:

   i = 0 vect[i] = 1

   i = 1 vect[i] = 2

   i = 2 vect[i] = 3

   i = 3 vect[i] = 4

   i = 4 vect[i] = 5

   i = 5 vect[i] = 6

   i = 6 vect[i] = 7

   i = 7 vect[i] = 8

   i = 8 vect[i] = 9

   i = 9 vect[i] = 0

   antherWay:

   i = 0 vect[i] = 1

   i = 1 vect[i] = 2

   i = 2 vect[i] = 3

   i = 3 vect[i] = 4

   i = 4 vect[i] = 5

   i = 5 vect[i] = 6

   i = 6 vect[i] = 7

   i = 7 vect[i] = 8

   i = 8 vect[i] = 9

   i = 9 vect[i] = 10

   */

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote