how to check if there is a division by zero in c

前端 未结 4 1911
暖寄归人
暖寄归人 2021-01-05 08:21
#include
void function(int);

int main()
{
     int x;

     printf(\"Enter x:\");
     scanf(\"%d\", &x);

function(x);

return 0;
}

void functi         


        
4条回答
  •  囚心锁ツ
    2021-01-05 09:01

    #include
    void function(int);
    
    int main()
    {
         int x;
    
         printf("Enter x:");
         scanf("%d", &x);
    
    function(x);
    
    return 0;
    }
    
    void function(int x)
    {
        float fx;
    
        if(x==0) // Simple!
            printf("division by zero is not allowed");
        else
            fx=10/x;            
            printf("f(x) is: %.5f",fx);
    
    }
    

提交回复
热议问题