Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- void choise();
- void distance();
- void hypotenus();
- void perimeter();
- void area_recetangle();
- void area_square();
- int main(void)
- {
- int user_choise = 1;
- while(user_choise>0 && user_choise<=6)
- {
- choise() ;
- scanf("%d", &user_choise);
- switch(user_choise)
- {
- case 1:
- distance();
- break;
- case 2:
- hypotenus();
- break;
- case 3:
- perimeter();
- break;
- case 4:
- area_recetangle();
- break;
- case 5:
- area_square();
- break;
- case 6:
- printf("goodbye");
- return (0);
- break;
- default:
- break;
- }
- }
- return (0);
- }
- /*
- this function calculates the choise
- */
- void choise()
- {
- printf("welcome to my calculator\n enter an option:\n1 - calc distance between 2 points\n2 - calc hypotenus triangle\n3 - calc area perimeter of circle\n4 - calc area of rectangle\n5 - area of square\n6 - exit");
- }
- /*
- this function calculates distance
- */
- void distance()
- {
- int x1 = 0;
- int x2 = 0;
- int y1 = 0;
- int y2 = 0;
- printf("pls enter the first two numbers\n");
- scanf("%d%d" , &x1 , &y1);
- getchar();
- printf("pls enter the second two numbers\n");
- scanf("%d%d" , &x2 , &y2);
- getchar();
- int defferencex = x2 - x1;
- int differencey = y2 - y1;
- double result = ((sqrt(pow(defferencex,2) + pow(differencey,2))));
- printf("distance is %lf\n" , result);
- }
- void hypotenus()
- {
- double x1 = 0;
- double x2 = 0;
- printf("pls enter the first two numbers\n");
- scanf("%lf%lf" , &x1 , &x2);
- double hypotenus = (sqrt(pow(x1,2) + pow(x2,2)));
- printf("%lf" , hypotenus);
- }
- void perimeter()
- {
- double radius = 0;
- printf("enter a radius");
- scanf("%lf" , &radius);
- double perimeter = radius*(2 * 3.14);
- double area = 3.14 * pow(radius,2);
- printf("%lf %lf" , perimeter , area);
- }
- void area_recetangle()
- {
- int width = 0;
- int length = 0;
- printf("enter the length\n");
- scanf("%d" , &length);
- printf("enter the width\n");
- scanf("%d" , &width);
- int area = length * width;
- printf("the area is: %lf\n" , area);
- }
- void area_square()
- {
- int width = 0;
- int length = 0;
- printf("enter the length\n");
- scanf("%d" , &length);
- printf("enter the width\n");
- scanf("%d" , &width);
- int area = length * width;
- printf("the area is: %lf\n" , area);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement