Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include void modifyArray(int b[], int size); void modifyElement(int e); int calculateSum(int n[]); int main(void) { int n[5] = {32, 27, 64, 18, 95}; int i,

#include

void modifyArray(int b[], int size);

void modifyElement(int e);

int calculateSum(int n[]);

int main(void)

{

int n[5] = {32, 27, 64, 18, 95};

int i, result;

int total = 0;

printf("Element Value ");

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

{

printf("%7u%13d ", i, n[i]);

total += n[i];

}

result = calculateSum(n);

printf("Total array elements values is %d ", total);

printf("Result array elements values is %d ", result);

modifyArray(n, 5);

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

{

printf("%7u%13d ", i, n[i]);

total += n[i];

}

printf("Total array elements values is %d ", total);

result = calculateSum(n);

printf("Result array elements values is %d ", result);

modifyElement(n[3]);

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

{

printf("%7u%13d ", i, n[i]);

total += n[i];

}

printf("Total array elements values is %d ", total);

result = calculateSum(n);

printf("Result array elements values is %d ", result);

}

int calculateSum(int n[])

{

int sum = 0;

int i;

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

{

sum += n[i];

}

return sum;

}

void modifyArray(int b[], int size)

{

int j;

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

{

b[j] *= 2;

}

}

void modifyElement(int e)

{

printf("Value in modifyElement is %d ", e *= 2);

}

  1. Now, declare the array to be of 4 elements, but initialize five, like this: int n[4] = {32, 27, 64, 18, 95};. Compile the program and run it. What happens to your output and why.
  2. Now, declare the array to be of 5 elements, but initialize 4 (delete the last value), like this: int n[5] = {32, 27, 64, 18 };. Compile the program and run it. What happens to your output and why.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago