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

1. Consider the factorial fact program given in Appendix A.6 on Pages A-27-A29.

ID: 3591993 • Letter: 1

Question

1. Consider the factorial fact program given in Appendix A.6 on Pages A-27-A29. Make it more efficient by decreasing its instruction count. What address is this program stored in the memory (Check in Spim)? Is it the starting address of the text segment given in Figure A.5.1 on Page A-21? [10 points]

Consider the factorial fact program given in Appendix A.6 on Pages A-27-A29. Make it more efficient by decreasing its instruction count. What address is this program stored in the memory (Check in Spim)? Is it the starting address of the text segment given in Figure A.5.1 on Page A- 21? [10 points] 1.

Explanation / Answer

#include <iostream>
#include <cmath>
using namespace std;

float calculateSD(float data[]);

int main()
{
int i;
float data[10];

cout << "Enter 10 elements: ";
for(i = 0; i < 10; ++i)
cin >> data[i];

cout << endl << "Standard Deviation = " << calculateSD(data);

return 0;
}

float calculateSD(float data[])
{
float sum = 0.0, mean, standardDeviation = 0.0;

int i;

for(i = 0; i < 10; ++i)
{
sum += data[i];
}

mean = sum/10;

for(i = 0; i < 10; ++i)
standardDeviation += pow(data[i] - mean, 2);

return sqrt(standardDeviation / 10);
}