Most of those functions can be shortened by removing the temporary variable and simply returning the result of the expression, like so:
Code:
float getfsin(float rad)
{
return (float)sin(rad);
}
From what I can see, getfdeg does nothing but read a value and return it. That's hardly an operation that warrants a function to perform so you could get away with doing that in main.
Code:
#include <stdio.h>
#include <math.h>
#define RAD 57.295779f
float getfrad(int deg){return deg/RAD;}
float getfsin(float rad){return (float)sin(rad);}
float getfcos(float rad){return (float)cos(rad);}
float getftan(float rad){return (float)tan(rad);}
int getfinc (int deg){return deg + 15;}
int main ( void )
{
int deg;
float rad;
float sin;
float cos;
float tan;
int inc;
printf("Please enter the degree to be evaluated then press enter.\t");
scanf(" %d", °);
rad = getfrad(deg);
sin = getfsin(rad);
cos = getfcos(rad);
tan = getftan(rad);
printf(" %d %f %f %f %f\n", deg, rad, sin, cos, tan);
inc = getfinc (deg);
rad = getfrad(inc);
sin = getfsin(rad);
cos = getfcos(rad);
tan = getftan (rad);
printf(" %d %f %f %f %f", inc, rad, sin, cos, tan);
getchar();
return 0;
}
If you really want to decrease the number of functions, you can write one processing function and send pointers to it. This is always another alternative and shortens the program drastically, but you lose a little bit of readability with a long parameter list for the function:
Code:
#include <stdio.h>
#include <math.h>
#define RAD 57.295779f
#define DEGREES 15
void getf ( int deg, float *prad, float *psin, float *pcos, float *ptan )
{
*prad = deg / RAD;
*psin = (float)sin(*prad);
*pcos = (float)cos(*prad);
*ptan = (float)tan(*prad);
}
int main ( void )
{
int deg;
float rad, sin, cos, tan;
printf("Please enter the degree to be evaluated then press enter.\t");
scanf(" %d", °);
getf ( deg, &rad, &sin, &cos, &tan );
printf(" %d %f %f %f %f\n", deg, rad, sin, cos, tan);
getf ( deg += DEGREES, &rad, &sin, &cos, &tan );
printf(" %d %f %f %f %f\n", deg, rad, sin, cos, tan);
getchar();
return 0;
}
What you choose to do depends on what you want out of the program, but all of the above work exactly the same as the code you posted.
-Prelude