Programa para determinar la distancia focal de un espejo esférico

Escriba un programa para determinar la distancia focal de un espejo esférico.
La distancia focal es la distancia entre el centro del espejo y los focos principales. Para determinar la distancia focal de un espejo esférico debemos conocer el radio de curvatura de ese espejo. La distancia del vértice al centro de curvatura se llama radio de curvatura. 
La distancia focal es la mitad del radio de curvatura. 
Fórmula :
 

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

Ejemplos: 
 

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

Javascript

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

Producción : 
 

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

Publicación traducida automáticamente

Artículo escrito por mohitw16 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *