Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

I am unsure on how I can printnt the difference between y and x

0 votes
asked Oct 13, 2022 by Arghavankas2022 (120 points)
#include <stdio.h>

#include <math.h>
#define PI 3.14159265

int main () {
   double y, mycos;
   printf("enter value in radian: \n");
   scanf("%lf", &y);

  
  

   mycos = cos(y) ;
   printf("The  cosine of %lf is %lf degrees", y, mycos);
    double x, myacos, val;
   printf("   enter value of cosine(between -1 and 1): \n");
   scanf("%lf", &x);

   
   val = 180.0 / PI;

   myacos = acos(x) * val;
   printf("The arc cosine of %lf is %lf degrees", x, myacos);
   
  
   
   return(0);

}

1 Answer

0 votes
answered Oct 20, 2022 by Peter Minarik (86,200 points)

Your output is confusing

printf("The  cosine of %lf is %lf degrees", y, mycos);

The result of a cos(x) is not measured in degrees, it has no unit of measurement. It is a real number in the range of [-1, 1]. In short, remove "degrees" from your line above. :)

How to print the difference between x and y.

This is confusing again...

Since both x and y are doubles, you can simply just print their differences:

printf("x - y = %lf", x - y);

I'm pretty sure you could have written the above code yourself and you wouldn't need others' help to write it. So again, I'm confused. :)

The difference calculated above doesn't really hold much physical meaning though: you're reducing an angle by a length. (A stupid example of mine: you go shopping then calculate the difference between how much you spent and how much the purchased items weigh. You can calculate it, but what does it mean?!)

What are you after?

I think first of all you'll need to figure out what you want to achieve here.

Maybe add more details to your question?

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...