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

This Question is from my C programming class. Book that we use is Ansi C 4th Edi

ID: 3824240 • Letter: T

Question

This Question is from my C programming class. Book that we use is Ansi C 4th Edition by Gary J Bronson. I'm on Chapter 7 currently.

Your task is to write a program that has a function. It should have these general characteristics: The program should not be longer than 30 lines. This should be a small task, nothing fancy. The program must contain a function. The task of the function is to be passed in a minimum of two variables and to change their value within the function. The main program will declare the variables (not global variables) and initialize them to some starting value, call the function, and print out the values of the variables after the function. You will need to have a prototype of the function. The variables can be char, int, or float.

Explanation / Answer

#include <stdio.h>
void square(int &a, int &b);

int main()
{
int a = 5, b =10;
printf("Before calling values a = %d , b = %d ",a,b);
square(a,b);
printf("After calling values a = %d , b = %d ",a,b);

return 0;
}

void square(int &a, int &b) {
a = a * a;
b =b * b;
}

Output:

sh-4.2$    g++ -o main *.cpp                                                                                                                                                                                                                                           

sh-4.2$ main                                                                                                                                                                                                                                                           

Before calling values a = 5 , b = 10                                                                                                                                                                                                                                   

After calling values a = 25 , b = 100

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote