Program for focal length of a lens | C ++ program to determine the focal length of a lens ; Function to determine the focal length of a lens ; Driver function ; variable to store the distance between the lens and the image ; variable to store the distance between the lens and the object
#include <iostream> NEW_LINE using namespace std ; float focal_length ( float image_distance , float object_distance ) { return 1 / ( ( 1 / image_distance ) + ( 1 / object_distance ) ) ; } int main ( ) { float image_distance = 2 ; float object_distance = 50 ; cout << " Focal ▁ length ▁ of ▁ a ▁ lens ▁ is ▁ " << focal_length ( image_distance , object_distance ) << " ▁ units ▁ . " ; return 0 ; }