187k views
4 votes
Write a complete C program to run on the MSP432 platform to do the following:

Declare an array of size 3 x 7 of type uint8_t. Use loops to initialize each array element to contain the value of the sum of its indices (e.g., for element arr[2][5], write a value of 7 to arr[2][5], write a value of 7 to arr[1][6], etc.). Use additional loops to go through the array and test each value – if a value is not a multiple of 5, add that value to a cumulative sum and write a zero to the array element. If it is a multiple of 5, leave it untouched. Print the final result as a 16-bit integer value (the sum of the array elements not multiples of 5). Be sure to compile it in CCS to catch any syntax errors.

1 Answer

6 votes

Answer:

The C code is given below with appropriate comments

Step-by-step explanation:

#include <stdio.h>

int main()

{

//array declaration

int arr[3][7], cumulativeSum = 0;

//initialize the array

for(int i=0; i<3; i++)

{

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

{

arr[i][j] = i+j;

}

}

//calculate the cumulative sum

for(int i=0; i<3; i++)

{

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

{

if((arr[i][j] % 5) != 0)

{

cumulativeSum += arr[i][j];

arr[i][j] = 0;

}

}

}

//display the final array

printf("The final array is: \\\\");

for(int i=0; i<3; i++)

{

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

{

printf("%d ", arr[i][j]);

}

printf("\\");

}

//display the cumulative sum

printf("\\Cumulative Sum = %d", cumulativeSum);

return 0;

}

User Joseline
by
5.4k points