-
1 Attachment(s)
Who can check my code?
//My program working but i don't know, i did it in correct way or not.?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
struct triagle
{
float point1;
float point2;
float point3;
};
float tr_perimetr(float x,float y,float z)
{
float perimetr;
perimetr = x+y+z;
return perimetr;
}
int main()
{
srand(time(NULL));
struct triagle perimetr;
int num;
perimetr.point1 = (rand()/(float)RAND_MAX)*(10.0+10.0)-10.0;
perimetr.point2 = (rand()/(float)RAND_MAX)*(10.0+10.0)-10.0;
perimetr.point3 = (rand()/(float)RAND_MAX)*(10.0+10.0)-10.0;
printf("Perimetr of triangle with edges of %.1f\t%.1f and %.1f = %.1f",perimetr.point1,perimetr.point2,perimetr.point3,tr_perimetr(perimetr.point1,perimetr.point2,perimetr.point3));
return 0;
}
-
Well, "triangle" has an 'n' in it.
And you aren't storing "points" but side lengths.
Also, the exercise says to pass a triangle to the function, not it's separate side lengths.
-
An point is normally considered two values often called x and y values.
Tim S.
-
john.c and stahta01 have a point (sorry didn't resist the pun).
You are dealing with triangle SIDES, not vertices. And choosing 3 random values between -10 and 10:
Code:
rand()/(float)RAND_MAX -> Will be a value between 0 and 1.
(rand() / (float)RAND_MAX) * 20 -> Will be a value between 0 and 20.
(rand() / (float)RAND_MAX) * 20 - 10 -> Will be a value between -10 and 10
Not all choosen values are valid as "lengths"...