📜  C球面镜焦距程序

📅  最后修改于: 2021-05-28 02:09:21             🧑  作者: Mango

焦距是镜的中心到主要焦点之间的距离。为了确定球面镜的焦距,我们应该知道该镜的曲率半径。从顶点到曲率中心的距离称为曲率半径。

焦距是曲率半径的一半。
公式 :

F =   ( R / 2 )      for concave mirror
F = - ( R / 2 )      for convex mirror

例子 :

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
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.


输出 :

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

有关更多详细信息,请参考完整的程序文章以确定球面镜的焦距!

想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。