Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math.h>
- #include <stdio.h>
- double setVars(double* a, double* b, double* c, double* S, double* P) {
- double semi;
- if(*a > 0 && *b > 0 && *c > 0) {
- *P = *a + *b + *c;
- semi = *P / 2;
- *S = sqrt(semi*(semi-*a)*(semi-*b)*(semi-*c));
- return 0;
- }
- return 2;
- }
- int main() {
- double a, b, c;
- double S = 0;
- double P = 0;
- while(scanf("%lf %lf %lf", &a, &b, &c) != EOF) {
- if(setVars(&a, &b, &c, &S, &P) == 0) {
- printf("S: %lf cm2\n", S);
- printf("P: %lf cm\n", P);
- } else {
- fprintf(stderr, "Invalid triangle sizes\n");
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment