您的位置:首页 > 其它

期末复习

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.

#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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: