gpt4 book ai didi

c - 如何检查c中是否有零除

转载 作者:太空狗 更新时间:2023-10-29 17:05:38 25 4
gpt4 key购买 nike

#include<stdio.h>
void function(int);

int main()
{
int x;

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

function(x);

return 0;
}

void function(int x)
{
float fx;

fx=10/x;

if(10 is divided by zero)// I dont know what to put here please help
printf("division by zero is not allowed");
else
printf("f(x) is: %.5f",fx);

}

最佳答案

#include<stdio.h>
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);

}

关于c - 如何检查c中是否有零除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2485547/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com