/* * Assignment5.c * Chapter 8 * By John Stile * Purpose: Create a new functions source file and header file with add two functions. * Write a program that employs the user functions in the new file. * * I stole my code from program Chapter 7, Project2.c. * Devided the code into 3 files: * * 1. Header file: Assignment5.headers.h * 2. Function file: Assignment5.funcitons.c (includes Assignment5.headers.h) * 3. Main file: Assignment5.c (include Assignment5.headers.h) * * Build it: Preprocessing --> Compilation --> Assembly --> Linking --> a.out * .i .s .o * // compile but don't link (don't load functions) * gcc -c Assignment5.c -o Assignment5.o * * // Compile but don't link (don't load functions) * gcc -c Assignment5.functions.c -o Assignment5.functions.o * * // Link objects, and includ math pow funciton * gcc Assignment5.o Assignment5.functions.o -lm -o Assignment5 */ #include #include #include "Assignment5.headers.h" #define DEBUG 0 int main(void) { int ii,xx,yy; // declare 3 integers float result=1; // declare 1 float printf("Input First "); // prompt for input xx=input_number(); printf("Input Second: "); // prompt for input yy=input_number(); if ( yy == 0 ) // easy calculation { print_result( xx, yy, 1); // print result return 0; } if ( xx == 1 ) // easy calcuation { print_result(xx, yy, xx); // print result } for( ii=1; ii<=yy; ii=ii+1) // run the loop yy times { if ( DEBUG == 1 ) { printf("xx=%d, ii=%d, result=%f\n", xx,ii,result); } result=(result*xx) ; // each time through, we multiply xx by the previous result } if ( (int)pow(xx,yy) == result ) { print_result(xx,ii,(int)result); } return 0; // return 0 to calling function }