c语言编程(x超过long范围)

[复制链接]
查看11 | 回复1 | 2010-12-15 17:57:03 | 显示全部楼层 |阅读模式
编写一程序实现以下功能
x(x只考虑整数int且必须定义为int、但F(x)完全可能超过int的表示范围)通过键盘输入(输入前给出提示Please input x:),然后计算并在屏幕上输出函数值。编程可用素材:printf("Please input x: ")...、printf("\nF(...) = ..."...。

┌ -5x+27 (x0)
┌ -5x+27 (x0)

回复

使用道具 举报

千问 | 2010-12-15 17:57:03 | 显示全部楼层
#include int main(void){ int x; float y; printf("Please input x:"); scanf("%d", &x); if (x < 0) {y = -5 * (float)x + 27; } else if (x == 0) {y = -7909; } else{y = 2 * (float)x - 1; } printf("\nF(%d)=%f", x, y); return 1;}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行