1690 - C语言程序设计教程(第三版)课后习题5.5
有一个函数
y={ x x<1
| 2x-1 1<=x<10
\ 3x-11 x>=10
写一段程序,输入x,输出y
Input
一个数x
Output
一个数y
Examples
Input
14
Output
31
Hint
使用函数
Solution C
#include<stdio.h> int main() { int x,y; while(scanf("%d",&x)!=EOF) { if(x<1) y=x; else if(x>=1&&x<10) y=2*x-1; else y=3*x-11; printf("%d\n",y); } return 0; }
Solution C++
#include<stdio.h> int tab(int x) { int y; if(x<1) y=x; else if(x<=1||x<10) y=2*x-1; else y=3*x-11; return y; } int main() { int x; scanf("%d",&x); printf("%d\n",tab(x)); return 0; }
Hint
使用函数