# Untitled

unknown
plain_text
3 years ago
2.2 kB
1
Indexable
Never
```#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
float num1, num2, geo_mean;
char waste;
int flag1, flag2, condition = 1;

printf("<Input a non-numerical input to terminate the program>\n");
printf("<Input your two numbers separated by a space>\n");

while((flag1 = scanf("%f", &num1)) == 1 && (flag2 = scanf("%f", &num2)) == 1){
if(num1*num2 >= 0){
geo_mean = sqrt(num1*num2);
printf("The geometric mean of %.2f and %.2f is %.2f.\n", num1, num2, geo_mean);
}
else{
printf("Invalid input. \nPlease try again: ");
}
scanf("%s", &waste);
}

//    float input_1, input_2, waste;
//    int number;
//    float geo_mean;
//    int flag1 = 0, flag2=0;
//
//
//    while ((flag1 = scanf("%f", &input_1) == 1 )&&(flag2=(scanf("%f", &input_2)) == 1))
//    {
//        if (input_1 * input_2 >= 0)
//        {
//            geo_mean = sqrt(input_1 * input_2);
//            printf("The geometric mean of %.2f and %.2f is %.2f\n", input_1,
//            input_2, geo_mean);
//        }
//        else
//    }
//    scanf("%s", &waste);
//    printf("SY2002103");

//    printf("<Enter a non-numerical input to exit the program>\n");
//    while(condition){
//        scanf("%f", &num1);
//        if(isdigit(num1) == 0){
//            break;
//        }
//        scanf("%f", &num2);
//        if(isdigit(num2) == 0){
//            break;
//        }
//        if(num1*num2 >= 0){
//            geo_mean = sqrt(num1*num2);
//            printf("The geometric mean is %.2f\n", geo_mean);
//        }
//        else{