Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct Triangulo{
- int X[3];
- int Y[3];
- }Triang;
- void escribir(Triang *);
- void mostrar(Triang *);
- void cambiar(Triang *);
- void distancia(Triang *, int , float *);
- int main(int argc, char *argv[])
- {
- int fin = 0;
- int opcion=0, opcion2;
- float dis;
- Triang T;
- while (fin == 0)
- {
- system("cls");
- printf("Menú simple\n\n");
- printf("\t1] Escribir Triangulo.\n");
- printf("\t2] Mostrar Coordenadas.\n");
- printf("\t3] Cambiar Coordenadas.\n");
- printf("\t4] Distancia Entre Puntos.\n");
- printf("\t5] Salir.\n");
- printf("\n\nOpcion: ");
- scanf("%i", &opcion);
- switch(opcion)
- {
- case 1:
- system("cls");
- escribir(&T);
- system("pause");
- break;
- case 2:
- system("cls");
- mostrar(&T);
- system("pause");
- break;
- case 3:
- system("cls");
- cambiar(&T);
- system("pause");
- break;
- case 4:
- system("cls");
- printf("Distancia\n\n");
- printf("\t1] Distancia AB.\n");
- printf("\t2] Distancia AC.\n");
- printf("\t3] Distancia BC.\n");
- printf("Seleccion: ");
- scanf("%d", &opcion2);
- distancia(&T, opcion2, &dis);
- system("pause");
- break;
- case 5:
- fin = 1;
- break;
- default:
- fin = 0;
- break;
- }
- }
- return 0;
- }
- void escribir(Triang *T)
- {
- Triang *T1;
- T1 = T;
- printf("Ingrese las coordenadas, en formato X1,Y1 X2,Y2 X3,Y3: \n");
- scanf("%d,%d %d,%d %d,%d)", &T1->X[0], &T1->Y[0], &T1->X[1], &T1->Y[1], &T1->X[2], &T1->Y[2]);
- }
- void mostrar(Triang *T)
- {
- Triang *T1;
- T1 = T;
- printf("\nLas coordenadas son A(%d,%d) B(%d,%d) C(%d,%d)\n", T1->X[0], T1->Y[0], T1->X[1], T1->Y[1], T1->X[2], T1->Y[2]);
- }
- void cambiar(Triang *T)
- {
- Triang *T1;
- T1 = T;
- printf("\nCoordenadas anteriores: A(%d,%d) B(%d,%d) C(%d,%d)\n", T1->X[0], T1->Y[0], T1->X[1], T1->Y[1], T1->X[2], T1->Y[2]);
- printf("Ingrese las nuevas coordenadas, en formato X1,Y1 X2,Y2 X3,Y3: \n");
- scanf("%d,%d %d,%d %d,%d)", &T1->X[0], &T1->Y[0], &T1->X[1], &T1->Y[1], &T1->X[2], &T1->Y[2]);
- }
- void distancia(Triang *T, int opcion2, float *dis)
- {
- Triang *T1;
- T1 = T;
- int A, B;
- if(opcion2==1)
- {
- A=T1->X[1]-T1->X[0];
- B=T1->Y[1]-T1->Y[0];
- *dis=sqrt(pow(A, 2)+ pow(B, 2));
- printf("Distancia de AB :\t%.2f\n", *dis);
- }
- if(opcion2==2)
- {
- A=T1->X[2]-T1->X[0];
- B=T1->Y[2]-T1->Y[0];
- *dis=sqrt(pow(A, 2)+ pow(B, 2));
- printf("Distancia de AC :\t%.2f\n",*dis);
- }
- if(opcion2==3)
- {
- A=T1->X[2]-T1->X[1];
- B=T1->Y[2]-T1->Y[1];
- *dis=sqrt(pow(A, 2)+ pow(B, 2));
- printf("Distancia de CB :\t%.2f\n",*dis);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment