C Exercises: Print out the corresponding value of sin(1/x) using 4-decimal places
C Basic Declarations and Expressions: Exercise-61 with Solution
Write a C program that accepts a real number x and prints out the corresponding value of sin(1/x) using 4-decimal places.
Note: Use 4-decimal places.
Test data and expected output:
Input value of x:
Value of sin(1/x) is 0.8415
Sample Solution:
C Code:
#include <stdio.h>
#include <math.h>
int main() {
double x, tval;
// Prompt user for input
printf("Input value of x: \n");
// Read the input value
scanf("%lf", &x);
if (x != 0.0) {
// Calculate sin(1/x) if x is not zero
tval = sin(1/x);
printf("Value of sin(1/x) is %0.4lf\n", tval);
} else {
// Display error message if x is zero
printf("Value of x should not be zero.");
}
return 0;
}
Sample Output:
Input value of x: Value of sin(1/x) is 0.9995
Flowchart:

C programming Code Editor:
Previous:Write a C program to create enumerated data type for 7 days and display their values in integer constants.
Next: Write a C program that accepts a positive integer less than 500 and prints out the sum of the digits of this number.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join