北邮信通复试题c语言,北邮计算机考研复试题的C语言解答精选.pdf

该篇博客介绍了一个C语言程序,用于将输入的十进制数字转换为无前导零的二进制表示。程序通过使用栈结构来存储和反转二进制位,从而避免了不必要的大数除法操作。示例输入和输出展示了程序的有效性,包括对多个数字的处理。
摘要由CSDN通过智能技术生成

北北邮邮计计算算机机考考研研复复试试题题的的C语语言言解解答答精精选选

二二进进制制数数

题目

题目描述:

大家都知道 数据在计算机里中存储是以二进制的形式存储的。

有一天 小明学了C语言之后 他想知道一个类型为unsigned int 类型的数字 存储在计算机中的二进制串是什么样子的

你能帮帮小明吗?并且 小明不想要二进制串中前面的没有意义的0 串 即要去掉前导0 。

输入:

第一行 一个数字T (T <=1000 ) 表示下面要求的数字的个数。

接下来有T 行 每行有一个数字n (0<=n<=10^8 ) 表示要求的二进制串。

输出:

输出共T 行。每行输出求得的二进制串。

样例输入:

5

23

535

2624

56275

989835

样例输出:

10111

1000010111

101001000000

1101101111010011

11110001101010001011

ac代码

没什么可说的 简单的机制转换 连大数除法都没考察!

#include

#include

#include

struct stack

{

int top;

int data[100];

};

void convert_to_binar (struct stack *s, unsigned long int d)

{

s->top = 0;

while (d) {

s->data[s->top ++] = d % 2;

d /= 2;

}

while (s->top) {

printf("%d", s->data[-- s->top]);

}

printf("\n");

}

int main()

{

int i, n;

unsigned long int d;

struct stack *s = (struct stack*)malloc(sizeof(struct stack));

while (scanf("%d", &n) != EOF) {

for (i = 0; i < n; i ++) {

scanf("%ld", &d);

if (d != 0) {

convert_to_binar (s, d);

}else {

printf("0\n");

}

}

}

return 0;

}

/**************************************************************

Pro lem : 1473

User: wangzhengyi

Language: C

Result: A ccepted

T ime:10 ms

Memory :904 k

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
期末作业要求如下: Write a program that will help elementary school pupils practice math. a) The program will first ask the user for his/her ID number (including two letters & 4 digits), e.g. Please input your four digit ID no: AB1234 The program should have input validation. Then the program prompts three choices: (1) Start a test (2) Check scores (3) Exit Test: the program will give 10 math problems, e.g.: 12 * 3 = 36 48 + 32 = 80 … 56 / 28 = 2 Note: i) Pupils will answer each problem before the next one is given. ii) The problems should include addition, subtraction, multiplication and division. They are randomly generated. iii) Randomly generates numbers for problems. However, must ensure that both the problem and the result are no larger than two digits. The problem and the result should be greater than or equal to zero. The divisor cannot be zero. iv) After ten problems are finished, record the time used by the student to do the ten problems. v) Gives a score to each student. Saves this student’s ID, his/her score and the time used into a file named ‘record.txt’. vi) Print the following information on the screen: Prob. | Correct Answ. | Ur Answ c) Check scores: Searches the file ‘record.txt’ and lists all the historical scores for this student, e.g.: Your previous records are: AB1234 80 150 seconds AB1234 50 182 seconds AB1234 90 98 seconds You will be marked based on your program’s: (1) Correctiveness (2) Readability (3) Robustness (4) Conciseness 目前本人的程序可以直接使用,并完全满足要求。还是建议学弟学妹在字里行间多多理解,争取自己写出漂亮的代码! 向本人在完成此作业过程中参的代码表示衷心的感谢!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值