SHOW:
|
|
- or go back to the newest paste.
| 1 | #include <stdio.h> | |
| 2 | #include <math.h> | |
| 3 | #include <stdlib.h> | |
| 4 | ||
| 5 | int area_rectang(int base, int height); | |
| 6 | int perim_rectang(int base, int height); | |
| 7 | int area_triang(int base, int height); | |
| 8 | int perim_triang(int side1,int side2,int side3); | |
| 9 | int area_circ(int ratio); | |
| 10 | int perim_circ(int ratio); | |
| 11 | int perim_paral(int base, int height); | |
| 12 | int area_cyl(int ratio, int height); | |
| 13 | int volum_cyl(int ratio, int height); | |
| 14 | int area_sphere(int ratio); | |
| 15 | int volum_sphere(int ratio); | |
| 16 | int area_prism(int lenght,int depth,int height); | |
| 17 | int volum_prism(int lenght, int depth,int height); | |
| 18 | int area_cone(int ratio, int height); | |
| 19 | int volum_cone(int ratio, int height); | |
| 20 | ||
| 21 | ||
| 22 | int main() | |
| 23 | {
| |
| 24 | int opc1=0, opt2=0; | |
| 25 | - | int base,height,ratio,lenght,side1,side2,side3,depth; |
| 25 | + | int base=0,height=0,ratio=0,lenght=0,side1=0,side2=0,side3=0,depth=0; |
| 26 | ||
| 27 | printf("Geocalc 1.0\n\n");
| |
| 28 | ||
| 29 | do{
| |
| 30 | - | fflush(stdin); |
| 30 | + | fflush; |
| 31 | system("cls");
| |
| 32 | printf("Selecciona la figura con la que deseas trabajar:\n\n");
| |
| 33 | printf("1) Cuadrado o rectangulo\n2) Triangulo\n3) Circulo\n4) Paralelogramo\n5) Cilindro\n6) Esfera\n7) Prisma rectangular\n8) Cono circular\n");
| |
| 34 | - | scanf("%i",&opc1);
|
| 34 | + | scanf("%i%*c",&opc1);
|
| 35 | ||
| 36 | system("cls");
| |
| 37 | ||
| 38 | if((opc1>=1)&&(opc1<=8)) | |
| 39 | {
| |
| 40 | switch(opc1) | |
| 41 | {
| |
| 42 | ||
| 43 | /* Rectangle figure*/ | |
| 44 | case 1: {printf("\nInserta la medida de la base\n");
| |
| 45 | - | scanf("%i",&base);
|
| 45 | + | scanf("%i%*c",&base);
|
| 46 | printf("\nInserta la medida de la altura\n");
| |
| 47 | - | scanf("%i",&height);
|
| 47 | + | scanf("%i%*c",&height);
|
| 48 | printf("\n\nArea: %i\nPerimetro: %i\n\n",area_rectang(base,height), perim_rectang(base,height));
| |
| 49 | break;} | |
| 50 | ||
| 51 | /*Triangle*/ | |
| 52 | case 2: {printf("\nInserta la medida de la base\n");
| |
| 53 | - | scanf("%i",&base);
|
| 53 | + | scanf("%i%*c",&base);
|
| 54 | printf("\nInserta la medida de la altura\n");
| |
| 55 | - | scanf("%i",&height);
|
| 55 | + | scanf("%i%*c",&height);
|
| 56 | printf("\nInserta la medida de los tres lados\n");
| |
| 57 | - | scanf("%i%i%i",&side1,&side2,&side3);
|
| 57 | + | scanf("%i%*c %i%*c %i%*c",&side1,&side2,&side3);
|
| 58 | printf("\n\nArea: %i\nPerimetro: %i\n\n",area_triang(base,height),perim_triang(side1,side2,side3));
| |
| 59 | break;} | |
| 60 | ||
| 61 | /*Circle*/ | |
| 62 | case 3: {printf("\nInserta el radio\n");
| |
| 63 | - | scanf("%i",&ratio);
|
| 63 | + | scanf("%i%*c",&ratio);
|
| 64 | printf("\n\nArea: %i\nPerimetro: %i\n\n",area_circ(ratio),perim_circ(ratio));
| |
| 65 | break;} | |
| 66 | ||
| 67 | /*Paralelogram*/ | |
| 68 | case 4: {printf("\nInserte la base\n");
| |
| 69 | - | scanf("%i",&base);
|
| 69 | + | scanf("%i%*c",&base);
|
| 70 | printf("\nInserte la altura\n");
| |
| 71 | - | scanf("%i",&height);
|
| 71 | + | scanf("%i%*c",&height);
|
| 72 | printf("\n\nArea: %i\nPerimetro: %i\n\n",area_rectang(base,height),perim_paral(base,height));
| |
| 73 | break;} | |
| 74 | /*Cylinder*/ | |
| 75 | case 5: {printf("\nInserte el radio\n");
| |
| 76 | - | scanf("%i",&ratio);
|
| 76 | + | scanf("%i%*c",&ratio);
|
| 77 | printf("\nInserte la altura\n");
| |
| 78 | - | scanf("%i",&height);
|
| 78 | + | scanf("%i%*c",&height);
|
| 79 | printf("\n\nArea: %i\nVolumen: %i\n\n",area_cyl(ratio, height),volum_cyl(ratio,height));
| |
| 80 | break;} | |
| 81 | ||
| 82 | /*Sphere*/ | |
| 83 | case 6: {printf("\n\nInserte el radio\n");
| |
| 84 | - | scanf("%i",&ratio);
|
| 84 | + | scanf("%i%*c",&ratio);
|
| 85 | printf("\n\nArea: %i\nVolumen: %i\n\n",area_sphere(ratio),volum_sphere(ratio));
| |
| 86 | break;} | |
| 87 | ||
| 88 | /*Rectangular prism*/ | |
| 89 | case 7: {printf("\n\nInserte la longitud\n");
| |
| 90 | - | scanf("%i",&lenght);
|
| 90 | + | scanf("%i%*c",&lenght);
|
| 91 | printf("\nInserte la profundidad\n");
| |
| 92 | - | scanf("%i",&depth);
|
| 92 | + | scanf("%i%*c",&depth);
|
| 93 | printf("\nInserte la altura\n");
| |
| 94 | - | scanf("%i",&height);
|
| 94 | + | scanf("%i%*c",&height);
|
| 95 | printf("\n\nArea: %i\nVolume: %i\n\n",area_prism(lenght,depth,height),volum_prism(lenght,depth,height));
| |
| 96 | break;} | |
| 97 | ||
| 98 | /*Circular cone*/ | |
| 99 | case 8: {printf("\n\nInserte el radio\n");
| |
| 100 | - | scanf("%i",&ratio);
|
| 100 | + | scanf("%i%*c",&ratio);
|
| 101 | printf("\nInserte la altura\n");
| |
| 102 | - | scanf("%i",&height);
|
| 102 | + | scanf("%i%*c",&height);
|
| 103 | printf("\n\nArea: %i\nVolumen: %i\n\n",area_cone(ratio,height),volum_cone(ratio,height));
| |
| 104 | break;} | |
| 105 | ||
| 106 | default: break;} | |
| 107 | } | |
| 108 | else {
| |
| 109 | printf("Opcion incorrecta");
| |
| 110 | getchar(); | |
| 111 | - | fflush(stdin); |
| 111 | + | |
| 112 | printf("\n\nDesea realizar otra operacion? 1) Si 2)No\n");
| |
| 113 | - | scanf("%i",&opt2);
|
| 113 | + | scanf("%i%*c",&opt2);
|
| 114 | }while(opt2==1); | |
| 115 | return 0; | |
| 116 | } | |
| 117 | ||
| 118 | //Functions | |
| 119 | /*Area of rectangle*/ | |
| 120 | int area_rectang(int base, int height) | |
| 121 | {
| |
| 122 | return (base*height); | |
| 123 | } | |
| 124 | ||
| 125 | /*Perimeter of rectangle*/ | |
| 126 | int perim_rectang(int base, int height) | |
| 127 | {
| |
| 128 | return (2*(base+height)); | |
| 129 | } | |
| 130 | ||
| 131 | /*Area of triangle*/ | |
| 132 | int area_triang(int base, int height) | |
| 133 | {
| |
| 134 | return (base*height)/2; | |
| 135 | } | |
| 136 | ||
| 137 | /*Perimeter of triangle*/ | |
| 138 | int perim_triang(int side1,int side2,int side3) | |
| 139 | {
| |
| 140 | return (side1+side2+side3); | |
| 141 | } | |
| 142 | ||
| 143 | /*Area of circle*/ | |
| 144 | int area_circ(int ratio) | |
| 145 | {
| |
| 146 | return M_PI*ratio*ratio; | |
| 147 | } | |
| 148 | ||
| 149 | /*Perimeter of Circle*/ | |
| 150 | int perim_circ(int ratio) | |
| 151 | {
| |
| 152 | return 2*M_PI*ratio; | |
| 153 | } | |
| 154 | ||
| 155 | ||
| 156 | /*Perimeter of Paralelogram*/ | |
| 157 | int perim_paral(int base, int height) | |
| 158 | {
| |
| 159 | return (2*base)+(2*height); | |
| 160 | } | |
| 161 | ||
| 162 | /*Area of cylinder*/ | |
| 163 | int area_cyl(int ratio, int height) | |
| 164 | {
| |
| 165 | return 2*M_PI*ratio*(ratio+height); | |
| 166 | } | |
| 167 | ||
| 168 | /*Volume of cylinder*/ | |
| 169 | int volum_cyl(int ratio, int height) | |
| 170 | {
| |
| 171 | return M_PI*ratio*ratio*height; | |
| 172 | } | |
| 173 | ||
| 174 | /*Area of sphere*/ | |
| 175 | int area_sphere(int ratio) | |
| 176 | {
| |
| 177 | return 4*M_PI*ratio*ratio; | |
| 178 | } | |
| 179 | ||
| 180 | /*volume of sphere*/ | |
| 181 | int volum_sphere(int ratio) | |
| 182 | {
| |
| 183 | return (4/3)*M_PI*pow(ratio,3); | |
| 184 | } | |
| 185 | ||
| 186 | /*Area of rectangular prism*/ | |
| 187 | int area_prism(int lenght,int depth,int height) | |
| 188 | {
| |
| 189 | return 2*(lenght*depth)+2*(depth*height)+2*(height*lenght); | |
| 190 | } | |
| 191 | ||
| 192 | /*Volume of rectangular prism*/ | |
| 193 | int volum_prism(int lenght, int depth, int height) | |
| 194 | {
| |
| 195 | return lenght*depth*height; | |
| 196 | } | |
| 197 | ||
| 198 | /*Area of cone*/ | |
| 199 | int area_cone(int ratio, int height) | |
| 200 | {
| |
| 201 | return M_PI*pow(ratio,2)*sqrt(pow(height,2)+pow(ratio,2)); | |
| 202 | } | |
| 203 | ||
| 204 | /*Volume of cone*/ | |
| 205 | int volum_cone(int ratio, int height) | |
| 206 | {
| |
| 207 | return (M_PI*pow(ratio,2)*height)/3; | |
| 208 | } |