C Online Compiler
Example: Generic Parabolic Vault Height Calculator (User Input) in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Generic Parabolic Vault Height Calculator (User Input) #include <stdio.h> #include <math.h> // Not strictly needed for vertex calc but good practice for math functions // Function to calculate the y-coordinate of a parabolic vault // y = k * x * (x - span), where k = -4 * rise / (span^2) double getParabolicY(double x, double span, double target_rise) { double k = -4.0 * target_rise / (span * span); return k * x * (x - span); } int main() { // Step 1: Declare variables for vault parameters double user_span; double user_target_rise; // This is the 'rise' we are aiming for in the equation // Step 2: Prompt user for vault span and desired rise printf("--- Generic Parabolic Vault ---\n"); printf("Enter the total span of the vault (e.g., 12.0): "); scanf("%lf", &user_span); printf("Enter the desired maximum height (rise) of the vault (e.g., 6.0): "); scanf("%lf", &user_target_rise); // Basic validation if (user_span <= 0 || user_target_rise <= 0) { printf("Span and rise must be positive values.\n"); return 1; // Indicate an error } // Step 3: Calculate the maximum height based on the user-defined function // For a symmetric parabola, the maximum height is at the midpoint of the span. double x_peak = user_span / 2.0; double actual_calculated_rise = getParabolicY(x_peak, user_span, user_target_rise); // Step 4: Print the calculated height printf("\nVault Details:\n"); printf(" Span: %.2f units\n", user_span); printf(" Desired Rise: %.2f units\n", user_target_rise); printf(" Calculated Maximum Height (Actual Rise): %.2f units\n", actual_calculated_rise); return 0; }
Output
Clear
ADVERTISEMENTS