Write a program to determine the focal length of a spherical mirror.
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
C++
// C++ program to determine // the focal length of a // of a spherical mirror #include<iostream> using namespace std; // Determines focal length // of a spherical concave // mirror float focal_length_concave(float R) { return R / 2 ; } // Determines focal length of a // spherical convex mirror float focal_length_convex(float R) { return - ( R / 2 ) ; } // Driver function int main() { float R = 30 ; cout << "Focal length of spherical" << "concave mirror is : " << focal_length_concave(R) << " units\n"; cout << "Focal length of spherical" << "convex mirror is : " << focal_length_convex(R) << " units"; return 0; } |
Java
// Java program to determine // the focal length of a // of a spherical mirror import java.util.*; import java.lang.*; public class GfG{ // Determines focal length // of a spherical concave // mirror public static float focal_length_concave(float R) { return R / 2 ; } // Determines focal length of a // spherical convex mirror public static float focal_length_convex(float R) { return - ( R / 2 ) ; } // Driver function public static void main(String argc[]) { float R = 30 ; System.out.print("Focal length of" + "spherical concave"+ "mirror is : "+ focal_length_concave(R) + " units\n"); System.out.println("Focal length of"+ "spherical convex"+ "mirror is : "+ focal_length_convex(R) + " units"); } } /* This code is contributed by Sagar Shukla */ |
Python
# Python3 program to determine # the focal length of a # of a spherical mirrorr # Determines focal length of # a spherical concave mirror def focal_length_concave(R): return R / 2 # Determines focal length of # a spherical convex mirror def focal_length_convex(R): return - ( R/ 2 ) # Driver function R = 30 ; print("Focal length of spherical concave mirror is :", focal_length_concave(R)," units") print("Focal length of spherical convex mirror is : ", focal_length_convex(R)," units") |
C#
// C# program to determine the focal // length of a of a spherical mirror using System; class GfG { // Determines focal length of a // spherical concave mirror public static float focal_length_concave(float R) { return R / 2 ; } // Determines focal length of a // spherical convex mirror public static float focal_length_convex(float R) { return - ( R / 2 ) ; } // Driver function public static void Main(String[] argc) { float R = 30 ; Console.Write("Focal length of" + "spherical concave" + "mirror is : " + focal_length_concave(R) + " units\n"); Console.Write("Focal length of" + "spherical convex" + "mirror is : " + focal_length_convex(R) + " units"); } } /* This code is contributed by parashar */ |
PHP
<?php //PHP program to determine // the focal length of a // of a spherical mirror // Determines focal length // of a spherical concave // mirror function focal_length_concave($R) { return $R / 2 ; } // Determines focal length of a // spherical convex mirror function focal_length_convex($R) { return - ( $R / 2 ) ; } // Driver function $R = 30 ; echo "Focal length of spherical", "concave mirror is : ", focal_length_concave($R), " units\n"; echo "Focal length of spherical", " convex mirror is : ", focal_length_convex($R), " units"; // This code is contributed by ajit ?> |
Output :
Focal length of spherical concave mirror is 15 units Focal length of spherical convex mirror is -15 units
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Program for focal length of a lens
- Program to determine the quadrant of the cartesian plane
- Program to determine the octant of the axial plane
- Program to determine the Quadrant of a Complex number
- Program for triangular pattern (mirror image around 0)
- Program to print mirror image of Swastika Pattern
- Program to Print Mirror Image of Sine-Wave Pattern
- Determine whether a given number is a Hyperperfect Number
- Determine the count of Leaf nodes in an N-ary tree
- Determine the number of squares of unit area that a given line will pass through.
- Determine the position of the third person on regular N sided polygon
- Determine whether the given integer N is a Peculiar Number or not
- Determine winner of the Game by arranging balls in a row
- Check if mirror image of a number is same if displayed in seven segment display
- Mirror of a point through a 3 D plane
- Check if the given array is mirror-inverse
- Program to find Length of Bridge using Speed and Length of Train
- Length of the chord the circle if length of the another chord which is equally inclined through the diameter is given
- Number of ways to cut a stick of length N into in even length at most K units long pieces
- Construct a string of length L such that each substring of length X has exactly Y distinct letters
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

