B
broli
#include<stdio.h>
#include<stdlib.h>
struct point
{
double x, y, z;
};
typedef struct point point;
struct triangle
{
point x,y, z;
};
typedef struct triangle triangle;
int main(void)
{
triangle *T;
T = malloc(sizeof(triangle));
printf("Enter the vertices of the triangle\n");
printf("First vertex:\n");
scanf("%lf %lf %lf", &(T->x.x), &(T->x.y), &(T->x.z));
printf("Second vertex:\n");
scanf("%lf %lf %lf", &(T->y.x), &(T->y.y), &(T->y.z));
printf("Third vertex:\n");
scanf("%lf %lf %lf", &(T->z.x), &(T->z.y), &(T->z.z));
printf("Vertex 1: %lf\t%lf\t%lf\n", T->x.x, T->x.y, T->x.z);
printf("Vertex 2: %lf\t%lf\t%lf\n", T->y.x, T->y.y, T->y.z);
printf("Vertex 3: %lf\t%lf\t%lf\n", T->z.x, T->z.y, T->z.z);
return 0;
}
I'm getting some garbage values in the output.
#include<stdlib.h>
struct point
{
double x, y, z;
};
typedef struct point point;
struct triangle
{
point x,y, z;
};
typedef struct triangle triangle;
int main(void)
{
triangle *T;
T = malloc(sizeof(triangle));
printf("Enter the vertices of the triangle\n");
printf("First vertex:\n");
scanf("%lf %lf %lf", &(T->x.x), &(T->x.y), &(T->x.z));
printf("Second vertex:\n");
scanf("%lf %lf %lf", &(T->y.x), &(T->y.y), &(T->y.z));
printf("Third vertex:\n");
scanf("%lf %lf %lf", &(T->z.x), &(T->z.y), &(T->z.z));
printf("Vertex 1: %lf\t%lf\t%lf\n", T->x.x, T->x.y, T->x.z);
printf("Vertex 2: %lf\t%lf\t%lf\n", T->y.x, T->y.y, T->y.z);
printf("Vertex 3: %lf\t%lf\t%lf\n", T->z.x, T->z.y, T->z.z);
return 0;
}
I'm getting some garbage values in the output.