Make your own free website on Tripod.com
back

Compile both programs with -lm option.

gcc pts.c -lm
gcc stp.c -lm


/*


  * takes the top speed as input and outputs the bhp
  */
#include <stdio.h>
#include <math.h>
 

main(int argc, char *argv[])
{
        float speed;
        if(argc != 2)
        {
                fprintf(stderr," Usage : %s topSpeed\n", argv[0]);
                exit(1);
        }
        speed = atof(argv[1]);
        speed /= 18;
        speed *= 5;
        printf("The BHP is %f\n", speed*speed*speed*0.0004861);
}
 
 



/*
 * takes the bhp as input and outputs the top speed
 */
#include <stdio.h>
#include <math.h>
 

main(int argc, char *argv[])
{
        float bhp, speed;
        if(argc != 2)
        {
                fprintf(stderr," Usage : %s bhp\n", argv[0]);
                exit(1);
        }
        bhp = atof(argv[1]);
        /*
         * divide the bhp by our constant and then find the cube root
         */
        speed = cbrt(bhp/0.0004861);
        /*
         * convert into kmph
         */
        speed *= 18;
        speed /= 5;
        printf("The top speed is %d kmphr\n", (int)speed);
}



 
 

back