用顺序栈实现十进制向二进制转化

#include<stdio.h>
#include<stdlib.h>
#define maxsize 30 
typedef int datatype;
typedef struct {
        datatype data[maxsize];
		int top; 
}SeqStack; 

int main() {
	SeqStack *S ;
	S = (SeqStack *)malloc(sizeof(SeqStack)); 
	S->top = -1;
    int i;
	printf("请输入一个十进制数:");
	scanf("%d",&i);
	while(i!=0){
		S->data[++S->top] = i%2;
		i/=2;
}
	printf("二进制为:");
	while(S->top!=-1){ 
	   printf("%d",S->data[S->top--]);
	}
} 
posted @ 2019-04-23 11:44  18软工2班苏炎  阅读(347)  评论(0编辑  收藏  举报