Lets write a C program to convert angle from Degree to Radian.
Formula To Convert Degree To Radian
radian = degree x (M_PI / 180.0);
where M_PI is a constant present in header file / library file math.h and its approximately equal to 3.14;
Note: Trigonometric Ratios like Sin, Cos, Tan etc take radian value as input and not degrees. So its important to learn how to convert angles from degree to radian.
#include<stdio.h>
#include<math.h>
int main()
{
const float PI = 3.14;
float r, h, s_area;
printf("Enter radius and height of the cone\n");
scanf("%f%f", &r, &h);
s_area = PI * r * ( r + sqrt(h * h + r * r) );
printf("Surface Area of Cone is %f\n", s_area);
return 0;
}
Output 1: Enter radius and height of the cone 8 18 Surface Area of Cone is 695.766663
Output 2: Enter radius and height of the cone 5 14 Surface Area of Cone is 311.897278
radian = degree x ( PI / 180.0) where PI is 3.14159265359
Note: In C programming Language, we’ve a builtin constant M_PI which has value of PI.
Expected Output for the Input
User Input: Enter angle in Degree 45
Output: Sum of square of sin(45.00) and cos(45.00) is 1
Logic To Check If Sum of Square of Sine and Cosine of an Angle is 1
User enters the angle in degree. We convert angle from degree to radian. radian = degree x ( PI / 180.0) Next we use pow() method present in math.h library to sqaure the values of sin(angle) and cos(angle). We add the square of sin(angle) and cos(angle) and store it inside the variable sum, and display appropriate message to the user.
Video Tutorial: C Program To Check If Sum of Square of Sine and Cosine of an Angle is 1
Given the coordinates(cx, cy) of center of a circle and its radius, write a C program that will determine whether a point(x, y) lies inside the Circle, on the Circle or outside the Circle. (Hint: Use sqrt() and pow() functions)
Note: Center Point – (cx, cy); We need to find the position of point (x, y);
Logic To Check whether Point Lies Inside, Outside or On The Circle
First we need to calculate the distance of the point(x, y) from the center(cx, cy) of the circle. Next we need to compare the distance with the radius of the Circle.
Conditions To Determine The Position of the Point(x, y) 1. Distance is greater than radius: point is outside the Circle. 2. Distance is less than radius : point is inside the Circle. 3. Distance is equal to the radius: point is on the Circle.
printf("Point (%0.2f, %0.2f) is inside the Circle\n", x, y);
}
elseif(distance > radius)
{
printf("Point (%0.2f, %0.2f) is outside the Circle\n", x, y);
}
else
{
printf("Point (%0.2f, %0.2f) is on the Circle\n", x, y);
}
return 0;
}
#include < stdio.h >
#include < math.h >
int main()
{
float cx, cy, radius, x, y, distance;
printf("Enter the center point(cx, cy)\n");
scanf("%f%f", &cx, &cy);
printf("Enter radius of the circle\n");
scanf("%f", &radius);
printf("Enter the point(x, y) to check its position\n");
scanf("%f%f", &x, &y);
distance = sqrt( pow( (x - cx), 2 ) + pow( (y - cy), 2 ) );
if(distance < radius)
{
printf("Point (%0.2f, %0.2f) is inside the Circle\n", x, y);
}
else if(distance > radius)
{
printf("Point (%0.2f, %0.2f) is outside the Circle\n", x, y);
}
else
{
printf("Point (%0.2f, %0.2f) is on the Circle\n", x, y);
}
return 0;
}
Output 1: Enter the center point(cx, cy) 0 0 Enter radius of the circle 6 Enter the point(x, y) to check its position 2 2 Point (2.00, 2.00) is inside the Circle
Output 2: Enter the center point(cx, cy) 0 0 Enter radius of the circle 6 Enter the point(x, y) to check its position 12 6 Point (12.00, 6.00) is outside the Circle
If user enters a number 123. i.e., num = 123; Then num % 10 would give the last digit of the number i.e., 3. To get first digit, we need to know the number of digits present in the number. To get that we make use of a built-in method called log10(). log10() returns the number of digits present in the number minus 1. That is because, it starts the count from 0. So if num = 123, log10(num) will return 2 and not 3. We store the number of digits inside variable count.
Now we use pow() method and calculate 10 to the power of count(value present in variable count) i.e., pow(10, count); We divide the user entered number by pow(10, count); to get the first digit of the number. i.e., First_Digit = num / pow(10, count);
Note: Both pow() and log10() are built-in methods present in header file math.h So we include that library file at the beginning of our C program source code.