Skip to content
Related Articles

Related Articles

C Program for focal length of a spherical mirror
  • Last Updated : 16 Mar, 2018
GeeksforGeeks - Summer Carnival Banner

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

CPP




// C++ program to determine
// the focal length 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
// spherical mirror
  
class GFG {
      
    // Determines focal length
    // of a spherical concave mirror
    static double focal_length_concave(double R)
    {
        return R / 2;
    }
      
    // Determines focal length of a
    // spherical convex mirror
    static double focal_length_convex(double R)
    {
        return -(R / 2);
    }
      
    // Driver function
    public static void main(String[] args)
    {
        double R = 30;
        System.out.println("Focal length of spherical " +
                           "concave mirror is : " +
                           (int)focal_length_concave(R) + 
                           " units");
        System.out.println("Focal length of spherical "
                           "convex mirror is : " +
                           (int)focal_length_convex(R) + 
                           " units");
    }
}
  
// This code is contributed by Azkia Anam.

Python3




# Python 3 program to determine
# the focal length of a
# spherical mirror
# 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 : ",
      "%d"%focal_length_concave(R)," units")
print("Focal length of spherical convex mirror is : ",
      "%d"%focal_length_convex(R)," units")
  
# This code is contributed
# by Azkia Anam.

C#




// C# program to determine 
// the focal length of a
// spherical mirror
using System;
class GFG 
{
      
    // Determines focal length
    // of a spherical concave mirror
    static double focal_length_concave(double R)
    {
        return R / 2;
    }
      
    // Determines focal length of a
    // spherical convex mirror
    static double focal_length_convex(double R)
    {
        return -(R / 2);
    }
      
    // Driver function
    public static void Main()
    {
        double R = 30;
        Console.WriteLine("Focal length of spherical " +
                        "concave mirror is : " +
                        (int)focal_length_concave(R) + 
                        " units");
        Console.WriteLine("Focal length of spherical "
                        "convex mirror is : " +
                        (int)focal_length_convex(R) + 
                        " units");
    }
}
  
// This code is contributed by vt_m.


Output :
Focal length of spherical concave mirror is 15 units
Focal length of spherical convex mirror is -15 units

Please refer complete article on Program to determine focal length of a spherical mirror for more details!

Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.




My Personal Notes arrow_drop_up
Recommended Articles
Page :