Ahoj vsem,
nebyl by tu nekdo tak hodny a pomohl mi s ukolem? V programovani jsem relativni zacatecnik a obavam se, ze tohle zadani je nad moje sily a chapani. Domnivam se, ze to ma byt sestrojene jako array[pocet_trojuhelniku][3].
1. Uzivatel ma byt vyzvan k zadani cisla (mnozstvi kontrolovanych trojuhelniku, >= 1, < UCHAR_MAX, musi to byt integer). To, myslim, mam v poradku.
int pocet_trojuhelniku;
int check = 0;
char letter_check;
float trojuhelnik[pocet_trojuhelniku][3];
do
{
printf("Please enter the number of triangles to check: \n");
scanf("%d", &anzahl_d);
scanf("%c", &letter_check);
if(letter_check != '\n')
{
while(getchar() != '\n')
{
}
check = 0;
}
if(anzahl_d >= 1 && anzahl_d < UCHAR_MAX)
{
check = 1;
}
if(pocet_trojuhelniku < 1 || pocet_trojuhelniku > UCHAR_MAX)
{
printf("[ERR] Invalid number of triangles.\n");
check = 0;
}
}
while(check == 0);
2. Uzivatel ma byt pocet_trojuhelniku-krat vyzvan k zadani velikosti stran ( > 0.0, < FLT_MAX, musi to byt float). A tady uz mam problemy s kontrolou, zda je vse zadano v poradku.
int counter;
for(counter = 0; counter < anzahl_d; counter++)
{
printf("Please enter the first number of the triplet: \n");
scanf("%f", &dreieck[counter][0]);
printf("Please enter the second number of the triplet: \n");
scanf("%f", &dreieck[counter][1]);
printf("Please enter the third number of the triplet: \n");
scanf("%f", &dreieck[counter][2]);
}
Kdyz jsem se snazila uplatnit vyse uvedene do, if, while, tak mi chodila hlaska "Segmenation fault".
A dal uz jsem uplne ztracena....
3. Razeni kazde trojice cisel (velikosti stran) od nejmensiho po nejvetsi. (bubble sort?)
4. Na zaklade a+b>c, a+c>b, b+c>a ma byt urceno, zda se jedna o trojuhelnik. Vystup ma vypadat takto: Triplet [number] (a=[a], b=[b], c=[c]) is a triangle. (prip. is NO triangle).
5. Pro kazdou trojici ma byt urceno, zda se jedna o rovnostranny trojuhelnik (a==b && b==c), rovnoramenny trojuhelnik (a==b || b==c || a==c), pripadne pravouhly trojuhelnik (a*a + b*b == c*c || b*b + c*c == a*a || a*a + c*c == b*b).
Body cislo 4 a 5 se mi podarilo vyresit pouze pro pripad propoctu jednohoh trojuhelniku, nevim, jak to nasadit na pole.
if((a + b) > c)
{
if((a + c) > b)
{
if((b + c) > a)
{
printf("Triplet (a=%f, b=%f, c=%f) is a triangle.\n", a, b, c);
}
}
}
else
{
printf("Triplet (a=%f, b=%f, c=%f) is no triangle.\n", a, b, c);
}
if(a==b && b==c)
{
printf("It is an equilateral triangle.\n");
}
if(a==b || b==c || a==c)
{
printf("It is an isosceles triangle.\n");
}
if(a*a + b*b == c*c || b*b + c*c == a*a || a*a + c*c == b*b)
{
printf("It is a right triangle.\n");
}
6. Pokud by melo po jakemkoli inputu nasledovat EOF, ma byt program bez dalsiho ukoncen.
Ukazka, jak to ma vypadat:
Please enter the number of triangles to check: 0
[ERR] Invalid number of triangles.
Please enter the number of triangles to check: 4
Please enter the first number of the triplet: 1
Please enter the second number of the triplet: 2
Please enter the third number of the triplet: foo
[ERR] Invalid number for the triplet.
Please enter the third number of the triplet: 1
Please enter the first number of the triplet: 4.5
Please enter the second number of the triplet: 7.24
Please enter the third number of the triplet: 4.5
Please enter the first number of the triplet: 11.7
Please enter the second number of the triplet: 11.7
Please enter the third number of the triplet: 11.7
Please enter the first number of the triplet: 3
Please enter the second number of the triplet: 4
Please enter the third number of the triplet: 5
Triplet 1 (a=1.000000, b=1.000000, c=2.000000) is NO triangle.
Triplet 2 (a=4.500000, b=4.500000, c=7.240000) is a triangle.
It is an isosceles triangle.
Triplet 3 (a=11.700000, b=11.700000, c=11.700000) is a triangle.
It is an equilateral triangle.
It is an isosceles triangle.
Triplet 4 (a=3.000000, b=4.000000, c=5.000000) is a triangle.
It is a right triangle.
Budu vdecna za jakoukoli pomoc....