#include "pch.h"
#include <iostream>
using namespace std;//
void allto2(void *p, int b) {
unsigned char n;
char f, *q;
for (f = 0, q = (char *)p + b - 1; q >= p; q--)
for (n = 0x80; n; n >>= 1) {
cout << (*q&n || 0);
f = 1;
}
cout << endl;
}
void main(void) {
double x;
float y;
int z;
char c;
cout << "Input a double-precision number...\nx=";
cin >> x;
allto2(&x, sizeof(x));
cout << "Input a floating number...\ny=";
cin >> y;
allto2(&y, sizeof(y));
cout << "Enter an integer...\nz=";
cin >> z;
allto2(&z, sizeof(z));
cout << "Enter a char...\nc=";
cin >> c;
allto2(&c, sizeof(c));
}
我想输入一个数程序自动判断是什么类型然后计算,我用了if语句但是没用,有没有大神帮帮忙