Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
User input and output with double in C
#1
Example:

double radius;
printf("Enter the radius of a circle: ");
scanf("%lf", &radius);
double area = 3.14159265359 * radius * radius;
printf("The area of the circle is: %.2lf\n", area);

Explanation:

In this example, we declare a double variable radius to store the user's input.
We prompt the user to enter the radius of a circle using printf().
We use the %lf format specifier in scanf() to read a double-precision value from the user and store it in the radius variable.
We calculate the area of the circle using the formula area = π * r^2, where π is approximated as 3.14159265359.
Finally, we print the calculated area using printf(). The .2 in the format specifier %.2lf ensures that the area is displayed with two decimal places.
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Basic arithmetic operations with the double datatype in C Qomplainerz 0 382 07-26-2023, 06:01 PM
Last Post: Qomplainerz
  Double datatype in C Qomplainerz 0 425 07-26-2023, 06:00 PM
Last Post: Qomplainerz
  User input and short int conversion in C Qomplainerz 0 391 07-26-2023, 03:49 PM
Last Post: Qomplainerz
  Working with floats from user input in C Qomplainerz 0 358 07-26-2023, 08:23 AM
Last Post: Qomplainerz
  Working with integers from user input in C Qomplainerz 0 377 07-26-2023, 08:19 AM
Last Post: Qomplainerz
  Input and Output functions (printf and scanf) in C Qomplainerz 0 244 07-25-2023, 10:52 AM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 1 Guest(s)