When i try to compile:
i get an error saying that the sqrt is not defined. I am usiing kate text editor for linux? where is sqrt defined when using linux?
Code:
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
/* Function Headers*/
double gravityFactor(double mass, double radius);
double escapeVelocity(double mass, double radius);
int main(void)
{
double mass, radius, gf, ev;
int unit;
double mass_pl[] = {3.3022e23, 4.8685e24, 5.9736e24, 7.3477e22, 6.4185e23,1.8986e27, 5.6846e26,
8.6810e25, 1.0243e26};
double rad_pl[] = {2439700, 6051800, 6371000, 1737100, 3396200, 71492000, 60268000, 25559000,
24764000};
do
{
printf("Select 1 for escape velocities and gravity factors.Select 2 to input own values: ");
scanf("%d", &unit);
}while((unit>2)||(unit<1));
if(unit==1)
{
printf("Stellar Body Gravity Factor Escape Velocity \n");
gf=((mass_pl[0]/mass_pl[2])/((rad_pl[0]/rad_pl[2])*(rad_pl[0]/rad_pl[2])));
ev =(sqrt((2*(6.67428e-11)*mass_pl[0])/rad_pl[0]))/1000;
printf(" Mercury: %.3f %.1f km/s\n", gf,ev);
gf=((mass_pl[1]/mass_pl[2])/((rad_pl[1]/rad_pl[2])*(rad_pl[1]/rad_pl[2])));
ev =(sqrt((2*(6.67428e-11)*mass_pl[1])/rad_pl[1]))/1000;
printf(" Venus: %.3f %.1f km/s\n", gf,ev);
gf=((mass_pl[2]/mass_pl[2])/((rad_pl[2]/rad_pl[2])*(rad_pl[2]/rad_pl[2])));
ev =(sqrt((2*(6.67428e-11)*mass_pl[2])/rad_pl[2]))/1000;
printf(" Earth: %.3f %.1f km/s\n", gf,ev);
gf=((mass_pl[3]/mass_pl[2])/((rad_pl[3]/rad_pl[2])*(rad_pl[3]/rad_pl[2])));
ev =(sqrt((2*(6.67428e-11)*mass_pl[3])/rad_pl[3]))/1000;
printf(" Moon: %.3f %.1f km/s\n", gf,ev);
gf=((mass_pl[4]/mass_pl[2])/((rad_pl[4]/rad_pl[2])*(rad_pl[4]/rad_pl[2])));
ev =(sqrt((2*(6.67428e-11)*mass_pl[4])/rad_pl[4]))/1000;
printf(" Mars: %.3f %.1f km/s\n", gf,ev);
gf=((mass_pl[5]/mass_pl[2])/((rad_pl[5]/rad_pl[2])*(rad_pl[5]/rad_pl[2])));
ev =(sqrt((2*(6.67428e-11)*mass_pl[5])/rad_pl[5]))/1000;
printf(" Jupiter: %.3f %.1f km/s\n", gf,ev);
gf=((mass_pl[6]/mass_pl[2])/((rad_pl[6]/rad_pl[2])*(rad_pl[6]/rad_pl[2])));
ev =(sqrt((2*(6.67428e-11)*mass_pl[6])/rad_pl[6]))/1000;
printf(" Saturn: %.3f %.1f km/s\n", gf,ev);
gf=((mass_pl[7]/mass_pl[2])/((rad_pl[7]/rad_pl[2])*(rad_pl[7]/rad_pl[2])));
ev =(sqrt((2*(6.67428e-11)*mass_pl[7])/rad_pl[7]))/1000;
printf(" Uranus: %.3f %.1f km/s\n", gf,ev);
gf=((mass_pl[8]/mass_pl[2])/((rad_pl[8]/rad_pl[2])*(rad_pl[8]/rad_pl[2])));
ev =(sqrt((2*(6.67428e-11)*mass_pl[8])/rad_pl[8]))/1000;
printf(" Neptune: %.3f %.1f km/s\n", gf,ev);
}
else if(unit==2)
{
do
{
printf("Please input the mass of your stellar body(In format:1.9891e30): ");
scanf("%lf", &mass);
printf("Please indicate the radius of your stellar body(In format:1234567): ");
scanf("%lf",&radius);
gravityFactor(mass, radius);
escapeVelocity(mass, radius);
printf("Please select 1 to calculate another planet. Press any number key to terminate: ");
scanf("%d", &unit);
}while(unit==1);
}
return 0;
}
double gravityFactor(double mass, double radius)
{
double gf;
gf =((mass/5.9736e24)/((radius/6371000)*(radius/6371000)));
printf("The gravity factor of this stellar body is: %.2f\n", gf);
return gf;
}
double escapeVelocity(double mass, double radius)
{
double ev;
ev =(sqrt((2*(6.67428e-11)*mass)/radius))/1000;
printf("The escape velocity of this stellar body is: %.2f km/s\n", ev);
return ev;
}
i get an error saying that the sqrt is not defined. I am usiing kate text editor for linux? where is sqrt defined when using linux?
Comment