Thread: functions problem (help)

  1. #1
    Registered User
    Join Date
    Oct 2018
    Posts
    12

    functions problem (help)

    i am trying to training my self to use functions and i start with easy tasks but i though that this task will work but the output is not show any result any idea why ?

    functions problem (help)-9991-png

    this is the task ....

    functions problem (help)-919-png


    functions problem (help)-991-png





    my code



    Code:
    #include<stdio.h>
    #include<math.h>
    #define PI 3.14
    double deg_to_radians (double t);
    double length_third_side (double n1,double n2,double tr);
    double calculateArea(double s,double n1,double n2, double n3 );
    
    
    int main ()
    {
        
        double n1,n2,n3,r,t,tr,s,a;
        printf("Enter the length of side 1 [cm] :\n" );
        scanf("%lf",&n1);
        printf("Enter the length of side 2 [cm] :\n");
        scanf("%lf",&n2);
        printf("Enter the angel in degrees bettween side1 and side 2:");
        scanf("%lf",&t);
        tr= deg_to_radians (t);
        n3= length_third_side (n1,n2,tr);
        s=(n1+n2+n2)/2.0;
        a= calculateArea(s,n1,n2,n3);
        
        printf ("The area of the triangle = %.2lf ",a);
        return 0;
        
    }
    
    
    double deg_to_radians (double t){
        double tr ;
        
        tr = t*PI/180.0;
        return tr;
    }
    double length_third_side (double n1,double n2,double tr){
        double n3;
        n3 =n1*n1*n2*n2-(2*n1*n2*cos(tr));
        return n3;
    }
    double calculateArea(double s,double n1,double n2, double n3 ){
        double a;
        a=sqrt(s*(s-n3)*(s-n1)*(s-n2));
        return a ; 
    
    
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Presumably s should involve n1, n2, and n3, rather than n1, n2, and n2.

  3. #3
    Registered User
    Join Date
    Oct 2018
    Posts
    12
    i fixed it but till the same


    ---------- turned out that the problem is i define a^2 not a so i just need to put a sqrt

  4. #4
    Registered User Kernelpanic's Avatar
    Join Date
    Sep 2018
    Location
    Berlin
    Posts
    105
    I can only assume where the mistake is in your program.
    The function deg_to_radians is not correct, the formula is:
    ((2 * PI) / 360) * winkel.
    For the computation of the third side you should use the pow-function -- maybe is there also a mistake in the program.


    This program run correct:

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #include <math.h>
    
    
    #define PI 3.14159
    
    
    //Deklaration
    double gradmass_in_bogenmass(double winkelgrad);
    double dreieck_dritte_seite(double a, double b, double radiant);
    double flaeche_dreieck(double a, double b, double c);
    
    
    int main(void)
    {
        double a, b, winkel;     
        
        system("cls");
        printf("\nBerechnung des Flaecheninhalts eines beliebigen Dreiecks\n\n");
        
        printf("Geben Sie die Laenge des Dreiecks von Seite a ein: ");
        scanf("%lf", &a);
        printf("Geben Sie die Laenge des Dreiecks von Seite b ein: ");
        scanf("%lf", &b);
        printf("Geben Sie den Winkel zwischen a und b ein        : ");
        scanf("%lf", &winkel);
        
        printf("\nDas Bogenmass betraegt           : %6.2lf rad", gradmass_in_bogenmass(winkel));
        printf("\nDie Laenge von Seite c betraegt  : %6.2lf cm", dreieck_dritte_seite(a, b, gradmass_in_bogenmass(winkel)));
        printf("\nDie Flaeche des Dreiecks betraegt: %6.2lf qcm\n", flaeche_dreieck(a, b, 
                                                             dreieck_dritte_seite(a, b, gradmass_in_bogenmass(winkel))));
        
        return(0);
    }
    
    
    double gradmass_in_bogenmass(double winkelgrad)
    {
        double radiant;
        
        radiant = (((2 * PI) / 360) * winkelgrad);
        return radiant;
    }
    
    
    double dreieck_dritte_seite(double a, double b, double radiant)
    {
        double y = 2.0;  //Hilfsvariable
        double seite_c;
        
        seite_c = sqrt((pow(a, y) + pow(b, y)) - (2 * a * b * cos(radiant)));
        return seite_c;
    }
    
    
    double flaeche_dreieck(double a, double b, double c)
    {
        double S, flaeche;
        
        S = ((a + b + c) / 2);
        flaeche = sqrt((S * ((S - a) * (S - b) * (S - c))));
        return flaeche;
    }
    functions problem (help)-dreieck-flaeche-jpg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. functions problem
    By alexvlc in forum C Programming
    Replies: 5
    Last Post: 11-25-2010, 02:47 PM
  2. problem with using functions
    By Drakon in forum C++ Programming
    Replies: 1
    Last Post: 03-28-2004, 08:09 PM
  3. Problem with functions
    By lizardking3 in forum C++ Programming
    Replies: 4
    Last Post: 09-22-2003, 04:34 PM
  4. Replies: 6
    Last Post: 05-06-2003, 03:08 PM
  5. Problem with two set of functions..
    By zahid in forum C Programming
    Replies: 7
    Last Post: 12-04-2002, 08:54 AM

Tags for this Thread