用顺序栈实现十进制向二进制转化
生活随笔
收集整理的這篇文章主要介紹了
用顺序栈实现十进制向二进制转化
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#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--]);}
}
轉載于:https://www.cnblogs.com/susususu/p/10755478.html
總結
以上是生活随笔為你收集整理的用顺序栈实现十进制向二进制转化的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: hashMap和hashTable的区别
- 下一篇: echart的x换行