Skip to content

Instantly share code, notes, and snippets.

@ChaseFlorell
Last active October 4, 2023 03:58
Show Gist options
  • Select an option

  • Save ChaseFlorell/c99d1ea9bd84ade74c16e90b3c9657a2 to your computer and use it in GitHub Desktop.

Select an option

Save ChaseFlorell/c99d1ea9bd84ade74c16e90b3c9657a2 to your computer and use it in GitHub Desktop.

Revisions

  1. ChaseFlorell revised this gist Oct 4, 2023. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions triange_validator.c
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,7 @@ Write your code in this editor and press "Run" button to compile and execute it.
    *******************************************************************************/

    #include <stdio.h>
    #include <stdbool.h>

    int
    main ()
    @@ -22,8 +23,9 @@ main ()
    printf ("Please enter angle #%i: ", i + 1);
    scanf ("%f", &angles[i]);
    }
    sum = sum + angles[i];
    sum += angles[i];
    }
    printf("Your triangle angles are %s", sum == 180 ? "valid" : "invalid");
    return sum != 180;
    }
    bool valid = sum == 180;
    printf("Your triangle angles are %s", valid ? "valid" : "invalid");
    return !valid; // invert because exit codes are dumb
    }
  2. ChaseFlorell revised this gist Oct 4, 2023. 1 changed file with 10 additions and 2 deletions.
    12 changes: 10 additions & 2 deletions triange_validator.c
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,26 @@
    /******************************************************************************
    Online C Compiler.
    Code, Compile, Run and Debug C program online.
    Write your code in this editor and press "Run" button to compile and execute it.
    *******************************************************************************/

    #include <stdio.h>

    int
    main ()
    {
    printf ("Triangle Validator\n\n");
    int angles[] = { 0, 0, 0 };
    float angles[] = { 0, 0, 0 };
    int i;
    float sum;
    for (i = 0; i < 3; i++)
    {
    while (angles[i] <= 0)
    {
    printf ("Please enter angle #%i: ", i + 1);
    scanf ("%d", &angles[i]);
    scanf ("%f", &angles[i]);
    }
    sum = sum + angles[i];
    }
  3. ChaseFlorell created this gist Oct 4, 2023.
    21 changes: 21 additions & 0 deletions triange_validator.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    #include <stdio.h>

    int
    main ()
    {
    printf ("Triangle Validator\n\n");
    int angles[] = { 0, 0, 0 };
    int i;
    float sum;
    for (i = 0; i < 3; i++)
    {
    while (angles[i] <= 0)
    {
    printf ("Please enter angle #%i: ", i + 1);
    scanf ("%d", &angles[i]);
    }
    sum = sum + angles[i];
    }
    printf("Your triangle angles are %s", sum == 180 ? "valid" : "invalid");
    return sum != 180;
    }