C Online Compiler
Example: Electromagnetic Wave Classifier in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Electromagnetic Wave Classifier #include <stdio.h> int main() { // Step 1: Declare a variable to store the wavelength double wavelength_meters; // Step 2: Prompt the user to enter the wavelength printf("Enter the wavelength in meters (e.g., 5e-7 for 5x10^-7): "); // Step 3: Read the wavelength from the user if (scanf("%lf", &wavelength_meters) != 1) { printf("Invalid input. Please enter a numerical value.\n"); return 1; // Indicate an error } // Step 4: Classify the wave based on its wavelength if (wavelength_meters < 1e-12) { // Less than 1 picometer printf("The wave is a Gamma Ray.\n"); } else if (wavelength_meters >= 1e-12 && wavelength_meters < 1e-8) { // 1 pm to 10 nm printf("The wave is an X-ray.\n"); } else if (wavelength_meters >= 1e-8 && wavelength_meters < 4e-7) { // 10 nm to 400 nm printf("The wave is Ultraviolet (UV) Light.\n"); } else if (wavelength_meters >= 4e-7 && wavelength_meters < 7e-7) { // 400 nm to 700 nm printf("The wave is Visible Light.\n"); } else if (wavelength_meters >= 7e-7 && wavelength_meters < 1e-3) { // 700 nm to 1 mm printf("The wave is Infrared (IR) Light.\n"); } else if (wavelength_meters >= 1e-3 && wavelength_meters < 1) { // 1 mm to 1 meter printf("The wave is a Microwave.\n"); } else if (wavelength_meters >= 1) { // Greater than or equal to 1 meter printf("The wave is a Radio Wave.\n"); } else { // Should ideally not be reached with positive wavelength, but for completeness printf("Unable to classify the wave (wavelength out of typical positive range).\n"); } return 0; // Indicate successful execution }
Output
Clear
ADVERTISEMENTS