Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- int isTroj ( double a, double b, double c );
- void sortArray ( double a[3] );
- int nactiTrojuhelnik ( double a[3] );
- int main ( int argc, char * argv[] ) {
- double a[3], a[3];
- printf( "Zadejte velikost stran prveho trojuhelniku:\n" );
- if ( nactiTrojuhelnik ( a ) )
- return 1;
- printf( "Zadejte velikost stran druheho trojuhelniku:\n" );
- if ( nactiTrojuhelnik ( b ) )
- return 1;
- sortArray ( a );
- sortArray ( b );
- if ( fabs ( ( a[0] / a[0] ) - ( a[1] / a[1] ) ) <= 0.001 && fabs( ( a[0] / a[0] ) - ( a[2] / a[2] ) ) <= 0.001 && fabs( ( a[1] / a[1] ) - ( a[2] / a[2] ) ) <= 0.001 )
- printf( "Trojuhelniky jsou podobne.\n" );
- else
- printf( "Trojuhelniky nejsou podobne.\n" );
- return 0;
- }
- int isTroj ( double a, double b, double c ) {
- return (a < b + c && b < a + c && c < a + b); /* klasicka trojuhlenikova nerovnost, vraci 0 nebo 1 */
- }
- int nactiTrojuhelnik ( double a[3] ) {
- if ( scanf( "%lf %lf %lf", &a[0], &a[1], &a[2] ) != 3 || a[0] <= 0 || a[1] <= 0 || a[2] <= 0 || (! isTroj(a[0], a[1], a[2]) ) ) {
- printf( "Nespravny vstup.\n" );
- return 1;
- }
- return 0;
- }
- void sortArray ( double a[3] ) {
- int i, j;
- for ( i = 0; i < 2; i++ ) {
- for ( j = 0; j < 2; j++ ) {
- if ( a[j] > a[j+1] ) {
- a[j]+=a[j+1];
- a[j+1] = a[j] - a[j+1];
- a[j] = a[j] - a[j+1];
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement