西南科技大学OJ题 进制转换问题0961
生活随笔
收集整理的這篇文章主要介紹了
西南科技大学OJ题 进制转换问题0961
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
進(jìn)制轉(zhuǎn)換問(wèn)題
建立順序棧或鏈棧,編寫(xiě)程序?qū)崿F(xiàn)十進(jìn)制數(shù)到二進(jìn)制數(shù)的轉(zhuǎn)換。
輸入
輸入只有一行,就是十進(jìn)制整數(shù)。輸出
轉(zhuǎn)換后的二進(jìn)制數(shù)。樣例輸入
10樣例輸出
1010 #include<stdio.h> #include<malloc.h> struct SqStack//棧結(jié)構(gòu) {int data[100];//儲(chǔ)存數(shù)據(jù) int top;//棧指針 }; void InitStack(SqStack *&s)//創(chuàng)建棧 {s=(SqStack*)malloc(sizeof(SqStack));//申請(qǐng)一個(gè)棧的空間,并且將s指向這個(gè)空間 s->top=-1;//初始化棧頂指針 } int main() {int n;struct SqStack *s;//聲明指針 scanf("%d",&n);InitStack(s);//創(chuàng)建棧 while(n!=0){s->top++;//棧頂加1 s->data[s->top]=n%2;//儲(chǔ)存模2的數(shù)據(jù),即入棧 n=n/2;}while(s->top!=-1)//輸出棧儲(chǔ)存的數(shù)據(jù),即出棧 {printf("%d",s->data[s->top]);s->top--;} }/* #include<stdio.h> int main() {int a,b[100];int i;scanf("%d",&a);for(i=0; ;i++){b[i]=a%2;a=a/2;if(a==0)break;}for( ;i>=0;i--)printf("%d",b[i]); } */?
總結(jié)
以上是生活随笔為你收集整理的西南科技大学OJ题 进制转换问题0961的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Thread.getContextCla
- 下一篇: 使用IAR软件的搜索快捷键出现中文繁体现