解题思路:
注意事项:
参考代码:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define maxsize 101
typedef struct
{
int num[maxsize];
int top;
}Sequenstack;
Sequenstack* init_sequenstack()
{
Sequenstack* s;
s = (Sequenstack*)malloc(sizeof(Sequenstack));
if (s == NULL)
return NULL;
s->top = -1;
return s;
}
int push_sequenstack(Sequenstack* s, int x)
{
if (s->top + 1 > maxsize)
{
return 0;
}
else
{
s->top++;
s->num[s->top] = x;
return 1;
}
}
int pop_sequenstack(Sequenstack* s, int* x)
{
if (s->top == -1)
return 0;
else
{
*x = s->num[s->top];
s->top--;
return 1;
}
}
int main()
{
int n,x,*a,m,sum=0;
a = (int*)malloc(sizeof(int));
Sequenstack* s;
s = init_sequenstack();
while (scanf("%d", &n) != EOF)
{
if (n == 0)
{
printf("0-->0\n");
}
else
{
m = n;
while (m != 0)
{
if (abs(m)>0&&abs(m)<2)
{
x = m % 2;
}
else
x = abs(m) % 2;
push_sequenstack(s, x);
m /= 2;
}
printf("%d-->", n);
while (s->top != -1)
{
pop_sequenstack(s, a);
printf("%d", *a);
}
printf("\n");
}
}
free(a);
return 0;
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题5.8 (C语言代码)浏览:806 |
P1002 (C语言代码)浏览:1019 |
【绝对值排序】 (C++代码)浏览:720 |
C语言程序设计教程(第三版)课后习题6.7 (C语言代码)浏览:548 |
A+B for Input-Output Practice (V) (C语言代码)浏览:640 |
C语言程序设计教程(第三版)课后习题6.11 (C语言代码)浏览:2098 |
最小公倍数 (C语言代码)浏览:1105 |
字符逆序 (C语言代码)浏览:645 |
图形输出 (C语言代码)浏览:1422 |
DNA (C语言代码)浏览:798 |