C++ 第40课转进制
作者:互联网
#include <iostream> #include <string> using namespace std; int main() { /*string a; int p = 1; int s = 0; cout<<"请输入一个二进制数:"; cin>>a; for(int i = a.length()-1;i>=0;i--){ int x = a[i]-'0'; s += x*p; p *= 2; } cout<<s<<endl; */ int a[10],n,i; cout<<"请输入一个十进制数:"; cin>>n; for(i=0;n>0;i++){ a[i] = n%2; n = n/2; } for(i=i-1;i>=0;i--){ cout<<a[i]; } return 0; }
标签:std,main,cout,int,C++,--,课转,40,include 来源: https://www.cnblogs.com/wangyihang/p/16684884.html