期末复习
2016-01-18 21:40
288 查看
Number 1
Write a program to determine the ranges of char , short , int , and long variables, both signed and unsigned , by printing appropriate values from standard headers.
No INPUT
And, your OUTPUT should be:
size of char is X
char max is X
char min is X
int min is X
int max is X
long min is X
long max is X
short min is X
short max is X
unsigned char max is X
unsigned long max is X
unsigned int max is X
unsigned short max is X
where you need to replace ‘X’ with the appropriate value.
Number 2
Now you have a rope with a length of C (may not be an integer).
You can form a circle or a square with the rope.
How much is the circle’s area larger than the square’s?
Sample Input
4
Sample Output
0.27
PI要自己define
Number3联合初试
Union是一种有趣的结构,虽然也许他并不常用。
现在由你定义一个union,并实现两个函数in_put和out_put
in_put会传入一个参数,一个变量x,当x为1时,给一个union读入一个int类型的值,并把这个union当做返回值返回,x为2时,读入double类型。
out_put会传入两个参数,一个union和一个变量x,当x为1时,输出这个union的int类型的值,当x为2时,输出这个union的double类型的值
输出double类型时保留两位小数
Write a program to determine the ranges of char , short , int , and long variables, both signed and unsigned , by printing appropriate values from standard headers.
No INPUT
And, your OUTPUT should be:
size of char is X
char max is X
char min is X
int min is X
int max is X
long min is X
long max is X
short min is X
short max is X
unsigned char max is X
unsigned long max is X
unsigned int max is X
unsigned short max is X
where you need to replace ‘X’ with the appropriate value.
#include<stdio.h> #include<limits.h> \\ remember include this head file int main() { printf("size of char is %d\n", CHAR_BIT); printf("char max is %d\n", CHAR_MAX); printf("char min is %d\n", CHAR_MIN); printf("int min is %d\n", INT_MIN); printf("int max is %d\n", INT_MAX); printf("long min is %ld\n", LONG_MIN); printf("long max is %ld\n", LONG_MAX); printf("short min is %d\n", SHRT_MIN); printf("short max is %d\n", SHRT_MAX); printf("unsigned char max is %d\n", UCHAR_MAX); printf("unsigned long max is %lu\n", ULONG_MAX); printf("unsigned int max is %u\n", UINT_MAX); printf("unsigned short max is %d\n", USHRT_MAX); return 0;
Number 2
Now you have a rope with a length of C (may not be an integer).
You can form a circle or a square with the rope.
How much is the circle’s area larger than the square’s?
Sample Input
4
Sample Output
0.27
PI要自己define
#include<stdio.h> #define PI 3.14159 int main() { double n; scanf("%lf", &n); int lc, ls; lc = (n*n)/(4*PI); ls = c*c/16; printf("%ld", lc - ls); return 0; }
Number3联合初试
Union是一种有趣的结构,虽然也许他并不常用。
现在由你定义一个union,并实现两个函数in_put和out_put
in_put会传入一个参数,一个变量x,当x为1时,给一个union读入一个int类型的值,并把这个union当做返回值返回,x为2时,读入double类型。
out_put会传入两个参数,一个union和一个变量x,当x为1时,输出这个union的int类型的值,当x为2时,输出这个union的double类型的值
输出double类型时保留两位小数
#include<stdio.h> union node{ int x; double v; }; union node in_put(int x); union node a; if (x == 1) { scnaf("%d", &a.x); } if (x == 2) scanf("%lf", &a.y); return a; } void out_put(union node a, int x) { if (x == 1) printf('%d\n", a.x); if (x == 2) printf("%.21lf\n", a.y); } int main() { union node a; a = in_put(1); out_put(a, 1); a = in_put(2); out_put(a, 2); }
相关文章推荐
- catalina.out
- Android学习(一)TextView,ImageView,Button,EditText,控件
- 扫描二维码
- 20130118
- 【BZOJ2199】 [Usaco2011 Jan]奶牛议会
- CentOS(6.5)安装lsb、查看系统版本信息
- Android笔记--对Android的四种LaunchMode和smail文件和scheme和http 的get、post的理解
- bzoj4305 数学
- R和JSON的傻瓜式编程
- Dijkstra + 优先队列优化 模板
- Tomcat普通用户启动注意事项
- Xcode6中手动添加Precompile Prefix Header
- Map集合
- C语言 - typedef关键字
- 【android基础二】android重要控件——你有多熟悉listview?
- 328. Odd Even Linked List
- 4000 视频采集处理之Z-Turn Board
- 11、ASP.NET MVC入门到精通——AspnetMVC分页
- 【BZOJ1823】 [JSOI2010]满汉全席
- 解决linux下主机名变bogon的问题