Any computer programmers out there I Need HELP!!!

Avatar image for master_thief
Master_Thief

1100

Forum Posts

3225

Wiki Points

0

Followers

Reviews: 2

User Lists: 1

How do I convert these intructions to code Im taking a programming with C class

// include the header file for stdio // include the header file for C mathematical library functions // function prototypes for two functions: // square: it is a function that receives a double value // and returns the square of the incoming value // sqroot: it is a function that receives a double value // and returns the square root of the incoming value int main( ) { double d; print( "please type a double: " ); scanf( "%lf", &d ); // display the value of d using %7.2lf // display the square of d using %7.2lf // display the square root of d using %7.2lf return 0; } // write the function square( ) double square( double x ) { // compute and return the square value of x } // write the function sqroot( ) // compute and return the square root value of x
Avatar image for dratini1331
Dratini1331

7916

Forum Posts

238

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

You can find most of it online. You can try this, though I'm probably dumb and forgot something.

#include <stdio.h>

#include <math.h>

double square(double x);

double sqroot(double x);

int main( ) { double d; print( "please type a double: " ); scanf( "%lf", &d ); // display the value of d using %7.2lf printf("Value: %7.2lf\n" , d); // display the square of d using %7.2lf  double squaredVal = square(d);
printf("Square: %7.2lf\n" , squaredVal);

// display the square root of d using %7.2lf 

double sqrtVal = sqroot(d);
printf("Square Root: %7.2lf\n" , sqrtVal);
return 0; }

double square(double x){

//this could also be pow(x, 2);

return x*x;

}

double sqroot(double x){

//This could also be sqrt(x) instead of pow, not sure if you can use sqrt

return pow(x, .5);

}