利用非遞迴的方式將十進位轉換成八進位,不過,方向有顛倒~~~
/* octnonrecu.c */
main(){
void oct(int);
int n;
printf("Enter an integer: ");
scanf("%d", &n);
while( n >= 8 ){
printf("%d", n % 8);
n = n / 8;
}
printf("%d\n", n);
/* 較高位會先列印出來,所以會顛倒 */
getch();
}
/* octnonrecu.c */
main(){
void oct(int);
int n;
printf("Enter an integer: ");
scanf("%d", &n);
while( n >= 8 ){
printf("%d", n % 8);
n = n / 8;
}
printf("%d\n", n);
/* 較高位會先列印出來,所以會顛倒 */
getch();
}
Copyright © 2010 Learning in free | Blogger Templates by Splashy Templates
Css Designed by Hot Website Templates
0 意見:
張貼留言