CQUPT计算机复试2015b卷代码题

CQUPT计算机复试2015b卷代码题

搬运请注明出处

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <math.h>
#include <stdlib.h>
#include <stack>
#include <queue>
#include <random>
using namespace std;
#define N 100
// insert
// void insert(int f, char str1[], char str2[])
// {
//     char str[N];
//     strcpy(str, str1 + f);
//     strcpy(str1 + f, str2);
//     strcat(str1, str);
// }
// int main(int argc, char const *argv[])
// {
//     char str1[N] = "abcdefgcomputer", str2[N] = "xyz";
//     int f = 4;
//     insert(f, str1, str2);
//     puts(str1);
//     return 0;
// }

// 各位数字之和
// void adddigit(int *m, int n, int *a)
// {
//     int *p, *q, x, k, sum;
//     p = m;
//     q = a;
//     for (int i = 0; i < n; i++, p++, q++)
//     {
//         x = *p;
//         sum = 0;
//         while (x)
//         {
//             k = x % 10;
//             sum += k;
//             x /= 10;
//         }
//         *q = sum;
//     }
// }
// int main(int argc, char const *argv[])
// {
//     int n, m[50], res[50];
//     do
//     {
//         cout << "n(<50)=";
//         cin >> n;
//     } while (n >= 50);
//     for (int i = 0; i < n; i++)
//     {
//         do
//         {
//             cout << "m(<32767)=";
//             cin >> m[i];
//         } while (m[i] >= 32767);
//     }
//     adddigit(m, n, res);
//     for (int i = 0; i < n; i++)
//     {
//         cout << m[i] << "->" << res[i] << endl;
//     }
//     return 0;
// }

// DecToBin
void DecToBin(unsigned int iDec, char pBin[])
{
    int n, k, i = 31;
    n = iDec;
    while (i >= 0)
    {
        k = n % 2;
        if (k == 1)
            pBin[i] = '1';
        else
            pBin[i] = '0';
        n /= 2;
        i--;
    }
    pBin[32] = '\0';
}
int main(int argc, char const *argv[])
{
    int n;
    char a[32];
    printf("n=");
    scanf("%d", &n);
    DecToBin(n, a);
    puts(a);
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值