Solved C Program: Basic Angle Calculation

In summary, the purpose of this C program is to calculate the value of an angle given its sine, cosine, or tangent ratio. To understand and use this program, you need to have a basic understanding of trigonometry and know how to use sine, cosine, and tangent ratios. You can input the known ratio and the program will calculate the angle, which can then be used in further calculations. This C program can be used for any triangle as long as you have the value of one of the trigonometric ratios. However, it cannot solve for angles using inverse trigonometric functions or advanced trigonometric concepts.
  • #1
ming2194
32
0
(*sovled) basic C program problem

Homework Statement


attrached.
and one more thing is:
if the angle is 90, a statement "This is a right angle." should be appeared in the last rows,
else, "This is not a right angle" instead.

also, the degee is 90 (interger) but not 90.0

Homework Equations


attrached


The Attempt at a Solution



#include<stdio.h>
int main ()
{ int degree;
float radian;

printf("Enter the angle in Degree:\n");
scanf( "%d", &degree );
printf("\nDegree is %d",&degree);

radian= degree/57.295779
printf("\nRadian is %3d",&radian);

if (degree!=90)
printf("\nThis is not a right angle");
else
printf("\nThis is a right angle");

return 0;
}

im just a beginner of writing c programe.
so maybe there many mistakes in my work.
plx forgiving that.
 

Attachments

  • c radian.JPG
    c radian.JPG
    22.8 KB · Views: 383
Last edited:
Physics news on Phys.org
  • #2
ming2194 said:

Homework Statement


attrached.
and one more thing is:
if the angle is 90, a statement "This is a right angle." should be appeared in the last rows,
else, "This is not a right angle" instead.

also, the degee is 90 (interger) but not 90.0

Homework Equations


attrached


The Attempt at a Solution



#include<stdio.h>
int main ()
{ int degree;
float radian;

printf("Enter the angle in Degree:\n");
scanf( "%d", &degree );
printf("\nDegree is %d",&degree);

radian= degree/57.295779
printf("\nRadian is %3d",&radian);

if (degree!=90)
printf("\nThis is not a right angle");
else
printf("\nThis is a right angle");

return 0;
}

im just a beginner of writing c programe.
so maybe there many mistakes in my work.
plx forgiving that.
You have one syntax error and several semantic errors. A syntax error is an error in how you have used the C programming language. The compiler will not produce an executable program when it encounters syntax errors. A semantic error is one in which C is used correctly by the program will produce incorrect values.

  1. The line below is incorrect.
    printf("\nDegree is %d",&degree);

    Remove the & from &degree. You are telling printf to print the address of degree, not the value stored there. The ampersand is needed in calls to scanf but not in calls to printf. There's an explanation for this, but you're probably not ready for it just yet.
  2. This line has your syntax error.
    radian= degree/57.295779
    Every statement in C must end with a semicolon.
  3. This line is incorrect for two reasons.
    printf("\nRadian is %3d",&radian);
    a. The & should not be used.
    b. The format specifier, %3d, does not match radian's type. Use %f instead.
 
  • #3
Mark44 said:
You have one syntax error and several semantic errors. A syntax error is an error in how you have used the C programming language. The compiler will not produce an executable program when it encounters syntax errors. A semantic error is one in which C is used correctly by the program will produce incorrect values.

  1. The line below is incorrect.
    printf("\nDegree is %d",&degree);

    Remove the & from &degree. You are telling printf to print the address of degree, not the value stored there. The ampersand is needed in calls to scanf but not in calls to printf. There's an explanation for this, but you're probably not ready for it just yet.
  2. This line has your syntax error.
    radian= degree/57.295779
    Every statement in C must end with a semicolon.
  3. This line is incorrect for two reasons.
    printf("\nRadian is %3d",&radian);
    a. The & should not be used.
    b. The format specifier, %3d, does not match radian's type. Use %f instead.

Thanks vy much for your correction.
i tested it in c-free programe and the sets work perfect.

but i want to ask is,

1. can i say the "&" is only needed to be added in scanf?

2. "radian= degree/57.295779" <-- it is okay to type decimal fraction in c programe?
or it is only valid if i specifiy the radian that is float at the beginning?
 
Last edited:
  • #4
ming2194 said:
but i want to ask is,
"radian= degree/57.295779" <-- it is okay to type decimal fraction in c programe?
or it is only valid if i specifiy the radian that is float at the beginning?
I'm not sure I understand your question. You can assign floating point literals (such as 57.295779) to floating point variables, such as float and double. You should not try to assign floating point values to variables that are int, long, short, char, and so on.

Edit: Added "not" to previous sentence.
 
Last edited:
  • #5
Mark44 said:
I'm not sure I understand your question. You can assign floating point literals (such as 57.295779) to floating point variables, such as float and double. You should try to assign floating point values to variables that are int, long, short, char, and so on.

can i say the "&" is only needed to be added in scanf?
 
  • #6
ming2194 said:
can i say the "&" is only needed to be added in scanf?
Most of the time, you need the & with scanf variable parameters but not with those in printf. The only time you don't need & with a scanf parameter is when the variable is already a pointer type. I'm sure you're not working with pointer variables yet, so I won't go into the reasons behind why & is used in scanf.

Note that I omitted one word in my previous post. I meant to say "You should NOT try to assign floating point values to variables that are int, long, short, char, and so on."
 

1. What is the purpose of this C program?

The purpose of this C program is to calculate the value of an angle given its sine, cosine, or tangent ratio.

2. What are the basic concepts needed to understand this C program?

To understand this C program, you should have a basic understanding of trigonometry and how to use sine, cosine, and tangent ratios to find the value of an angle.

3. How do I use this C program to solve an angle calculation?

To use this C program, you need to input the value of the known ratio (sine, cosine, or tangent) and the program will calculate the corresponding angle. You can then use this value in your calculations.

4. Can I use this C program to solve for angles in any triangle?

Yes, this C program can be used to solve for angles in any triangle, as long as you have the value of one of the trigonometric ratios (sine, cosine, or tangent) for that angle.

5. Are there any limitations to this C program?

This C program can only solve for angles using the three basic trigonometric ratios. It cannot solve for angles using inverse trigonometric functions or other advanced trigonometric concepts.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
12
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
837
  • Engineering and Comp Sci Homework Help
Replies
1
Views
8K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
879
  • Engineering and Comp Sci Homework Help
Replies
17
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
21
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
2K
Back
Top