This repository has been archived on 2023-10-26. You can view files and clone it, but cannot push or open issues or pull requests.
VSMechatronics/Exercises/C8/ex7.c

26 lines
705 B
C

#include <stdio.h>
#include <math.h>
int main() {
int rc; // used to check return codes of scanf
float radius, height;
printf("Enter radius: ");
rc = scanf("%f", &radius);
// scanf returns number of scanned items. If input is invalid then 0 values will have been scanned.
if (rc != 1) {
printf("Please enter an positive real integer or decimal\n");
return 1;
}
printf("Enter height: ");
rc = scanf("%f", &height);
// scanf returns number of scanned items. If input is invalid then 0 values will have been scanned.
if (rc != 1) {
printf("Please enter an positive real integer or decimal\n");
return 1;
}
printf("Surface area: %f\n", 2*M_PI*radius*radius + 2*M_PI*radius*height);
}