/* * Project1.c * Chapter 8 * By John Stile * Purpose: Write a short program that calls several functions from main. * Prototype the functions. * Define the funcitons after main. * Include 1 funciton for each of the following: * 1. Function does nto accept arguments but returns an int * 2. Fucntion accepts an int and float, returns a float * 3. Fucntion accepts char arguments and returns int. * 4. Fucntion accepts two char arguments and returns nothing. */ #include #define PI 3.141592 //////////////////////////////////////////////////// int func1(void); // Proto: takes nothing, returns int float func2(int, float); // Proto: takes int and float, returns float int func3(char); // Proto: takes char, returns int void func4(char,char); // Proto: takes 2 char, returns nothing //////////////////////////////////////////////////// int main(void) { // declare variables needed to pass to functions char aa, bb; // declare 2 chars int cc; // declare 1 int float dd; // declare 1 float cc=func1(); // Prompt user to input an int printf("You entered %d\n", cc); // show them what was input dd=func2( cc, PI); // Find Area, assign to float dd printf("If %d was a radius, the Area would be %f\n", cc,dd); printf ("Enter a character: "); // prompt for inmput scanf("%c", &aa); // read standard in, assign to location of cc getchar(); // clear buffer printf ("Enter another character: "); // prompt for inmput scanf("%c", &bb); // read standard in, assign to location of cc cc=func3(aa); // Call function, printf(" Your letters ascii value :\t%4d\n",cc); cc=func3(aa); // Call function, printf(" Your other letters ascii value:\t%4d\n",cc); func4(aa,bb); return 0; } //////////////////////////////////////////////////// int func1(void) // header for inputing a radios { int xx; printf("Please enter a integer: "); // prompt for an int scanf("%d", &xx ); // read standard input, assign to address of xx getchar(); // flush the input buffer return (xx); } //////////////////////////////////////////////////// float func2(int xx, float yy) // header for area = PI r^2 { return ( yy*xx*xx ); } //////////////////////////////////////////////////// int func3(char xx) { return( (int)xx ); } //////////////////////////////////////////////////// void func4( char aa, char bb) { printf( " You like the letters %c and %c\n", aa, bb); }