#include #include int main() { /*Start declaring variables*/ float V; /* Voltage */ float I; /* Current */ float R; /* Resistance */ float frequency; /* Frequency */ float X_L; /* Reactance */ float Z; /* Impedance */ float L; /* Inductance*/ const float pi = 3.14f; char c[10]; int i,counter; int checktriangle(int num1, int num2, int num3) { /* must be positive numbers */ if (num1 <= 0 || num2 <= 0 || num3 <= 0) return 0; /* the sum of any two sides must be greater than the other one */ if (num1 + num2 <= num3) return 0; if (num1 + num3 <= num2) return 0; if (num3 + num2 <= num1) return 0; return 1; } int checkscalene(int num1, int num2, int num3) { if (num1 == num2 || num1 == num3 || num2 == num3) return 0; return 1; } int checkright(int num1, int num2, int num3) { int sqr1 = num1 * num1; int sqr2 = num2 * num2; int sqr3 = num3 * num3; /* right triangle: a2 + b2 = c2 */ if (sqr1 + sqr2 == sqr3) return 1; if (sqr1 + sqr3 == sqr2) return 1; if (sqr3 + sqr2 == sqr1) return 1; return 0; } /* print the information */ printf("This program will input Voltage, Current, Resistance, Frequency\n"); printf("Then output Voltage, Current, Impedance, Reactance, Inductance\n"); do { /* ask for input */ printf("\nEnter Voltage, Current, Resistance, Frequency values\n"); printf("Separated with a space then press Enter:\n"); scanf("%f%f\%f%f", &V, &I, &R, &frequency); /* calculate the result */ Z = (V/I); X_L = (float)pow((Z*Z-R*R),(1/2)); L = X_L/(2*pi*frequency); /* output the result */ printf("The result: %.02f %.02f %.02f %.02f %.02f\n", V, I, Z, X_L, L); /* ask the user to continue */ printf("\nWould you like to enter another (y/n): "); scanf("%s", c); } while (c[0] == 'y' || c[0] == 'Y'); /* Promts user to enter either capital or small letter y*/ printf("Type in your number of input(s)\n"); scanf("%i", &counter); for (i=1; i<=counter; ++i) { printf("\nEnter Voltage, Current, Resistance, Frequency values\n"); printf("Separated with a space then press Enter:\n"); scanf("%f %f %f %f", &V, &I, &R, &frequency); /* calculate the result */ Z = (V/I); X_L = (float)pow((Z*Z-R*R),(1/2)); L = X_L/(2*pi*frequency); /* output the result */ printf("The result: %.02f %.02f %.02f %.02f %.02f\n", V, I, Z, X_L, L); } char reply[128];/*Character limitation*/ int num1, num2, num3; int istriangle; int isscalene; int isright; do { /* ask the user to enter 3 integers */ printf("Enter 3 integers separated with spaces then press ENTER: "); scanf("%d", &num1); scanf("%d", &num2); scanf("%d", &num3); istriangle = isscalene = isright = 0; /* check whether it is a triangle */ istriangle = checktriangle(num1, num2, num3); if (istriangle) { /* check scalene triangle, right triangle */ isscalene = checkscalene(num1, num2, num3); isright = checkright(num1, num2, num3); } /* print the result */ if (istriangle) printf("[%d %d %d] is a triangle\n", num1, num2, num3); else printf("[%d %d %d] is not a triangle\n", num1, num2, num3); if (isscalene) printf("[%d %d %d] is a scalene triangle\n", num1, num2, num3); else printf("[%d %d %d] is not a scalene triangle\n", num1, num2, num3); if (isright) printf("[%d %d %d] is a right triangle\n", num1, num2, num3); else printf("[%d %d %d] is not a right triangle\n", num1, num2, num3); /* ask the user to enter another */ printf("Would you like to enter another? (y/n): "); scanf("%s", reply); } while (reply[0] == 'y'); printf("\n\n"); system("pause"); return 0; }