C Program for focal length of a spherical mirror
Last Updated :
24 Oct, 2023
Focal length is the distance between the center of the mirror to the principal foci. In order to determine the focal length of a spherical mirror we should know the radius of curvature of that mirror. The distance from the vertex to the center of curvature is called radius of curvature. The focal length is half the radius of curvature.
Formula :
F = ( R / 2 ) for concave mirror
F = – ( R / 2 ) for convex mirror
Examples :
For a convex mirror
Input: R = 30
Output: F = 15
For a convex mirror
Input: R = 25
Output: F = – 12.5
Below is the Implementation of the above approach:
C
#include <stdio.h>
// Function to calculate the focal length of a spherical
// concave mirror
float focal_length_concave(float R) { return R / 2; }
// Function to calculate the focal length of a spherical
// convex mirror
float focal_length_convex(float R) { return -R / 2; }
// Drivers Code
int main()
{
float R = 30; // Radius of the spherical mirror (you can
// change this value)
// Calculate and print the focal length of a spherical
// concave mirror
printf("Focal length of spherical concave mirror is: "
"%.0f units\n",
focal_length_concave(R));
// Calculate and print the focal length of a spherical
// convex mirror
printf("Focal length of spherical convex mirror is: "
"%.0f units\n",
focal_length_convex(R));
return 0;
}