Question
Due: Before the beginning of the next lab . No late labs will be accepted . Please note that the assignment submission folder will be
Due: Before the beginning of the next lab . No late labs will be accepted.
Please note that the assignment submission folder will be unavailable after this time.
All your programs must include a Programmers Block and an explainProg function.
Format for the Programmers Block:
Description:
Programmer:
Date:
Version:
Output of all programs must be included with your code.
Using the following source file, from the debugger, create watch variables for
index, sum and number.
#include
#include
void square(int number);
int sum;
int main(void)
{
int index;
for (index = 1; index <= 7; index++)
square(index);
system("pause");
return(0);
}
void square(int number)
{
int numsq;
numsq = number * number;
sum = sum + numsq;
printf(" \t\t\tThe square of %d is %d ", number, numsq);
printf(" \t\t\tThe sum of the squares is %d ", sum);
return;
}
What does the watch window state about number when you are tracing outside the
function square()?
Why ( --- think of scope --- )?
What does the watch window state about index when you are tracing inside the
function square()?
Why ( --- think of scope --- )?
6) Modify the program as follows:
A) Make the global variable sum local to main() and make the program do exactly the
same thing.
Hint: return the square of the number from the function square() and do the summing
inside main() or initialize sum in main and pass it to square().
B) Make the global variable sum local to the function square(). Do the summing inside
the function.
Hint: Think about a static variable.
Submit both modified programs as well as the answers to parts 2 to 5
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started