Power of a lens
Last Updated :
20 Feb, 2023
Write a program to determine the power of a lens .
Power of a lens is its ability to bend light . For a convex lens, the converging ability is defined by power and in a concave lens, the diverging ability . The diopter ( D ) is the unit of measuring power of a lens .
The power is defined as the reciprocal of the focal length in meters .
D = ( 1 / F )
Here, D is the power in diopter,
F is the focal length in meters.
Examples:
Input : F = 2
Output : D = 0.5
Input : F = 0.2
Output : D = 5
C++
#include <iostream>
using namespace std;
float power( float focal_length)
{
return (1 / focal_length);
}
int main()
{
float focal_length = 2;
cout << "The power of the lens in diopter is "
<< power(focal_length);
return 0;
}
|
Java
import java.io.*;
class GFG
{
static float power( float focal_length)
{
return ( 1 / focal_length);
}
public static void main (String[] args)
{
float focal_length = 2 ;
System.out.println( "The power of the lens in diopter is "
+ power(focal_length));
}
}
|
Python3
def power( focal_length ) :
return ( 1 / focal_length )
focal_length = 2 ;
print ( "The power of the lens in diopter is " , end = "")
print (power(focal_length) )
|
C#
using System;
class GFG
{
static float power( float focal_length)
{
return (1 / focal_length);
}
public static void Main ()
{
float focal_length = 2;
Console.WriteLine( "The power of the lens in diopter is "
+ power(focal_length));
}
}
|
PHP
<?php
function power( $focal_length )
{
return (1 / $focal_length );
}
$focal_length = 2;
echo "The power of the lens in diopter is "
, power( $focal_length );
?>
|
Javascript
<script>
function power( focal_length)
{
return (1 / focal_length);
}
let focal_length = 2;
document.write( "The power of the lens in diopter is "
+ power(focal_length));
</script>
|
Output
The power of the lens in diopter is 0.5
Time Complexity: O(1)
Auxiliary Space: O(1)
Source:
http://www.bbc.co.uk/bitesize/intermediate2/physics/waves_and_optics/power_of_lens/revision/1/
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...