Skip to content

Instantly share code, notes, and snippets.

@grebenkov
Created January 29, 2022 13:57
Show Gist options
  • Save grebenkov/bdc6733bec0faa62008fcdeaa67637fb to your computer and use it in GitHub Desktop.
Save grebenkov/bdc6733bec0faa62008fcdeaa67637fb to your computer and use it in GitHub Desktop.
Annular section simple implementation in C
#define _USE_MATH_DEFINES
#include <math.h>
double annsec_MomentOfInertia (double insideD, double outsideD) {
return M_PI * (pow(outsideD, 4) - pow(insideD, 4)) / 64;
}
double annsec_PolarMomentOfInertia (double insideD, double outsideD) {
return M_PI * (pow(outsideD, 4) - pow(insideD, 4)) / 32;
}
double annsec_Area (double insideD, double outsideD) {
return M_PI * (pow(outsideD, 2) - pow(insideD, 2)) / 4;
}
#pragma once
double annsec_MomentOfInertia (double insideD, double outsideD);
double annsec_PolarMomentOfInertia (double insideD, double outsideD);
double annsec_Area (double insideD, double outsideD);
#include <stdio.h>
#include "annularsection.h"
int main(void) {
double insideD, outsideD;
double area, moi, polarmoi;
printf("Enter inside diameter:\n");
while(scanf("%lf",&insideD) != 1) {
printf("Wrong input, please retry:\n");
}
printf("Enter outside diameter:\n");
while(scanf("%lf",&outsideD) != 1) {
printf("Wrong input, please retry:\n");
}
area = annsec_Area(insideD, outsideD);
moi = annsec_MomentOfInertia(insideD, outsideD);
polarmoi = annsec_PolarMomentOfInertia(insideD, outsideD);
printf("Area: %lf\n", area);
printf("Moment of inertia: %lf\n", moi);
printf("Polar moment of inertia: %lf\n", polarmoi);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment