#️⃣ C# A help po mga paps di na kaya ng AI

Rojen G Embate

Honorary Poster
Write a c program that will ask the user to enter the length and height of a trapezoid. Find its are. Use the formula

A = ((a+b/2)*h
a = length of base 1
b = length of base 2
h = height of the trapezoid
A = area of trapezoid

Sample output 1
Enter the value of base 1: 0
Invalid value!

Sample output 2
Enter the value of base 1: 2.67
Enter the value of base 2:;-7.98
Invalid value

Sample output 3
Enter the value of base 1: 1.2345
Enter the value of base 2: 5.678
Enter the value of height: 0
Invalid value!
 
Here's a C program that calculates the area of a trapezoid based on the given formula:

C:
#include <stdio.h>

int main() {
    double a, b, h, area;

    printf("Enter the value of base 1: ");
    if (scanf("%lf", &a) != 1 || a <= 0) {
        printf("Invalid value!\n");
        return 0;
    }

    printf("Enter the value of base 2: ");
    if (scanf("%lf", &b) != 1 || b <= 0) {
        printf("Invalid value!\n");
        return 0;
    }

    printf("Enter the value of height: ");
    if (scanf("%lf", &h) != 1 || h <= 0) {
        printf("Invalid value!\n");
        return 0;
    }

    area = ((a + b) / 2) * h;
    printf("The area of the trapezoid is: %.2lf\n", area);

    return 0;
}

In this program, we first prompt the user to enter the value of base 1, then validate the input to ensure it's a positive number. If the input is invalid, we display an error message and exit the program.

Next, we prompt the user to enter the value of base 2, perform the same validation, and display an error message if necessary.

Finally, we prompt the user to enter the value of the height, validate it, and display an error message if necessary.

If all inputs are valid, we calculate the area using the given formula and display it with two decimal places.
 
Hahaha dapat di mo na yan ipasolve sa ᑕᕼᗩTGᑭT, kaya may ganyang problems para matrain yung logical and critical thinking. Tsaka kana magpatulong sa AI pag gamay mo na yung language. You can thank me later pagsinunod mo payo ko.
 

About this Thread

  • 2
    Replies
  • 336
    Views
  • 2
    Participants
Last reply from:
Xirvana

Online now

Members online
954
Guests online
1,433
Total visitors
2,387

Forum statistics

Threads
2,276,192
Posts
28,968,184
Members
1,231,159
Latest member
Cuong Pham
Back
Top