#include<stdio.h>#define scan(a, b) scanf("%lf,%lf", &a, &b)#define print(a, b) a > b ? printf("%.2lf,%.2lf\n", a, b) : printf("%.2lf,%.2lf\n", b, a)intmain(){
double a, b;scan(a, b);print(a, b);return0;}
#include<stdio.h>#define MAX(x, y, z) x > y &&x > z ? x : (y > z && y > x ? y : (z > x && z > y ? z : 1))intmain(){
double x, y, z;scanf("%lf,%lf,%lf",&x,&y,&z);printf("MAX=%.2lf\n",MAX(x, y, z));return0;}
实验07(03)位运算取一个数中的某一位
题目描述
编写函数,实现将一个数(unsigned short)n 中的第 m 位取出来,并输出该位的值(从右
到左第 m 位)。
输入描述
输入:依次输入无符号数 n 和位数 m,逗号为英文。
输出描述
输出:第 m 位的值。
输入样例
5,1
输出样例
0
#include<stdio.h>voidff(unsignedshort n,int m);intmain(){
unsignedshort n, m;scanf("%hu,%hu",&n,&m);ff(n, m);return0;}voidff(unsignedshort n,unsignedshort m){
unsignedshort z;
z =((n &(1<< m))>> m);printf("%hu\n", z);}
#include<stdio.h>voidff(unsignedint a);intmain(){
unsignedint a;scanf("%d",&a);ff(a);return0;}voidff(unsignedint a){
unsignedint x, y, z, t;
x = a &0xff;
y = x &0xaa;
t = x &0x55;
z =(~y)&0xff-0x55+ t;printf("%d\n", z);}
#include<stdio.h>voidff(int n);intmain(){
int n;scanf("%d",&n);ff(n);return0;}voidff(int n){
unsignedshort a, x, y;
a =0x5545;
x = a << n;
y = a >>(16- n);printf("%0x\n", x + y);}
#include<stdio.h>#include<math.h>voidmain(){
unsignedint x, y;unsignedintafter(unsignedint a);scanf("%d",&x);
y =after(x);printf("%0x\n", y);}unsignedintafter(unsignedint a){
int i, b =0;for(i =0; i <7; i++)
b +=(a &(1<< i));if(b %2==0)
a =(a &~0)+(unsignedint)(1<<7);else
a =(a &~(unsignedint)(1<<7));return(a);}