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

Write the following program as one program in C : 1. Create an array of 100 rand

ID: 3693502 • Letter: W

Question

Write the following program as one program in C:

1. Create an array of 100 random numbers in the range of 1…999, write a function for each of the following processes. In building the array, if 3 or 7 evenly divide the random number, store it as a negative number.

a. Print the array ten values to a line. Make sure that the values are aligned in rows.

b. Return a count of the number of even values

     c. Return the sum of all values in the array

2. Create a two dimensional array (size 10 X 10). Fill this two dimensional array with the values from the above single dimensional array. Determine the maximum value in each row. Display the two-dimensional array and the maximum of each row.

3. Repeat number 2 above but this time instead of 10 X 10 array, prompt the user for the size of the row and column, allow user to fill in the values and display the array.(Hint: Use pointers and dynamic memory allocation )

Explanation / Answer

C Program to find sum of elements in a given array

/* C Program to find sum of elements in a given array */

#include <stdio.h>

#define MAX_SIZE 1000

// C program to return sum of elements in an array of size n

int sum(int arr[], int n)

{

    int sum = 0; // initialize sum

    int i;

    // Iterate through all elements and add them to sum

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

       sum += arr[i];

    return sum;

}

int main()

{

    int arr[MAX_SIZE];

    int n, i;

    printf("Eneter the number of elements in array ");

    scanf("%d", &n);

    printf("Enter Elements ");

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

      scanf("%d", &arr[i]);

    printf("Sum of the elements is %d", sum(arr, n));

    return 0;

}

/* C Program to find sum of elements in a given array */

#include <stdio.h>

#define MAX_SIZE 1000

// C program to return sum of elements in an array of size n

int sum(int arr[], int n)

{

    int sum = 0; // initialize sum

    int i;

    // Iterate through all elements and add them to sum

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

       sum += arr[i];

    return sum;

}

int main()

{

    int arr[MAX_SIZE];

    int n, i;

    printf("Eneter the number of elements in array ");

    scanf("%d", &n);

    printf("Enter Elements ");

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

      scanf("%d", &arr[i]);

    printf("Sum of the elements is %d", sum(arr, n));

    return 0;

}