In this question, we are sharing a c program to get the focal length of a lens in c programming.
Copy the below c program and execute it to see the program output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include <stdio.h> // Function to find the focal length of a lens float focal_length(float image_distance, float object_distance) { return 1 / ((1 / image_distance) + (1 / object_distance)); } // main function int main() { // distance between the lens and the image float image_distance = 5; // distance between the lens and the object float object_distance = 10; printf("Focal length of a lens is: %f\n", focal_length(image_distance, object_distance)); return 0; } |
Output
1 | Focal length of a lens is: 3.333333 |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.