Program to determine focal length of a spherical mirror - GeeksforGeeks

12 Apr, 2021
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++
Java
Python
C#
PHP
Javascript
// 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// mirrorfloat focal_length_concave(float R){    return R / 2 ;} // Determines focal length of a// spherical convex mirrorfloat focal_length_convex(float R){    return - ( R / 2 ) ;} // Driver functionint 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 program to determine// the focal length of a// of a spherical mirrorimport 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 */
# Python3 program to determine# the focal length of a# of a spherical mirrorr # Determines focal length of# a spherical concave mirrordef focal_length_concave(R):    return R / 2 # Determines focal length of# a spherical convex mirrordef focal_length_convex(R):    return - ( R/ 2 ) # Driver functionR = 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# program to determine the focal// length of a of a spherical mirrorusing 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 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 mirrorfunction 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?>
<script> // javascript 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          let R = 30 ;                   document.write("Focal length of" +                         "spherical concave"+                         "mirror is : "+                         focal_length_concave(R) +                         " units" + "<br/>");                                   document.write("Focal length of"+                           "spherical convex"+                           "mirror is : "+                           focal_length_convex(R) +                           " units");           // This code is contributed by susmitakundugoaldanga.</script>
Output :  
Focal length of spherical concave mirror is 15 units
Focal length of spherical convex mirror is -15 units
 
parashar
jit_t
susmitakundugoaldanga
Mathematical
School Programming
Mathematical
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Program to print prime numbers from 1 to N.
Segment Tree | Set 1 (Sum of given range)
Modular multiplicative inverse
Count all possible paths from top left to bottom right of a mXn matrix
Fizz Buzz Implementation
Python Dictionary
Arrays in C/C++
Inheritance in C++
Reverse a string in Java
C++ Classes and Objects