程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> 問題一百三十六:三角形類問題

問題一百三十六:三角形類問題

編輯:關於C語言

[plain]  #include <stdio.h> 
#include <math.h> 
#include <stdlib.h> 
 
float calculate_perimeter(float x, float y, float z); 
float calculate_area(float x, float y, float z); 
int   judge_triangle(float x, float y, float z); 
int   judge_righttriangle(float x, float y, float z); 
int   judge_isoscelestriangle(float, float y, float z); 
int   judge_equilateraltriangle(float x, float y, float z); 
int main() 

      float x; 
      float y; 
      float z; 
           
      scanf("%f %f %f", &x, &y, &z); 
       
      if(judge_triangle(x, y, z)) 
      { 
             printf("The area of a triangle is %f.\nThe perimeter of a triangle is %f.\n", 
                    calculate_area(x, y, z), calculate_perimeter(x, y, z)); 
             if(judge_righttriangle(x, y, z)) 
             { 
                  printf("The triangle is right triangle!\n");                          
             } 
             else  
             { 
                  printf("The triangle is not right triangle!\n");      
             }      
              
             if(judge_isoscelestriangle(x, y, z)) 
             { 
                  printf("The triangle is isoscelestriangle!\n");                               
             } 
             else 
             { 
                  printf("The triangle is not isoscelstriangle\n");     
             } 
              
             if(judge_equilateraltriangle(x, y, z))   
             { 
                  printf("The triangle is equilateraltriangle!\n");                                 
             }              
             else 
             { 
                  printf("The triangle is not equlateraltriangle!\n");     
             } 
      } 
      else 
      { 
          printf("x, y and z cann`t form a triangle!\n");     
      } 
       
      system("pause"); 
      return 0; 

 
//definetion of function 
//**judge triangle 
int judge_triangle(float x, float y, float z) 

    int flag; 
     
    flag=0; 
     
    if(x+y> z || x+z> y || y+z> x) 
    { 
         flag=1;            
    }     
     
    return flag; 

 
//**calculate perimeter 
float calculate_perimeter(float x, float y, float z) 

      float perimeter; 
       
      perimeter=x+y+z; 
       
      return perimeter;      

 
//**calculate area 
float calculate_area(float x, float y, float z) 
{     
     float s; 
     float area; 
      
     s=calculate_perimeter(x, y, z)/2; 
     area=sqrt((s-x)*(s-y)*(s-z)*s);    
      
     return area;       

 
//**judge righttriagnle  
int  judge_righttriangle(float x, float y, float z) 
{      
      int flag; 
       
      flag=0; 
       
      if(x*x+ y*y ==z*z || x*x+ z*z==y*y || z*z+ y*y==x*x) 
      { 
          flag=1;         
      }       
       
      return flag; 

 
//** judge isoscelestriangle 
int  judge_isoscelestriangle(float x, float y, float z) 

      int flag; 
       
      flag=0; 
       
      if(x==y || x==z || y==z) 
      {    
          if(x==y && y==z && x==z) 
          { 
             flag=0;         
          } 
          else 
          { 
             flag=1; 
          } 
      } 
       
      return flag; 

 
//**judge equilateraltriangle 
int judge_equilateraltriangle(float x, float y, float z) 
{   
     int flag; 
      
     flag=0; 
      
     if(x==y && y==z && x==z) 
     { 
         flag=1;         
     } 
      
     return flag; 
}  

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved