/* * question6.c * FINAL * BY: John Stile * Purpose: * Prompt user for 2 numbers. * pass pointers to variables holding the numbers to a function * that squares the values, returning nothing. * Then main should output the squared values. * a) PLAN: * what piece would you write first. * what would its functionality be? * How would you modify the first piece to become the second. * b) Follow your plan. * * PLAN: write program skeleton (prototypes, headers) * prompt for user input * add section to prompt for input * write function prottype and header * write the function * test */ #include void square( int *, int *); // takes 2 pointers, returns nothing int main(void) { int a, b; // declare 2 itns printf("Enter fist number: "); // prompt for input scanf( "%d", &a ); // read from stdin, and store as digit getchar(); // clear input buffer printf("Enter second number: "); // prompt for input scanf( "%d", &b ); // read from stdin, and store as digit square( &a, &b ); // call function, passing addresses of a and b printf("\nThe square of the first is: %d\n", a); // print result printf("The square of the second is: %d\n", b); // print result return 0; } void square( int * first, int * second) // takes 2 int pointers, returns nothing { *first=(*first)*(*first); // square the frist number. re-assign in place *second=(*second)*(*second); // square the second number, re-assign in place return; // return nothing }