
求解一道简单的C语言题
编一个程序,输入一个十进制数,输出相应的十六进制数或者输入二进制输出八进制……总之就是这一类的题怎么做啦~~...
编一个程序,输入一个十进制数,输出相应的十六进制数
或者输入二进制输出八进制……总之就是这一类的题怎么做啦~~ 展开
或者输入二进制输出八进制……总之就是这一类的题怎么做啦~~ 展开
展开全部
一:输入十进制,输出八、十、十六进制。
#include <stdio.h>
int main(void)
{
int n;
scanf("%d", &n);
printf("八进制:%o\n", n);
printf("十进制:%d\n", n);
printf("十六进制:%x\n", n);
return 0;
}
例子:
16
八进制:20
十进制:16
十六进制:10
Press any key to continue
二:输入二进制,输出八、十、十六进制
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
char string[128];
long n;
scanf("%s", string);
n = strtol(string, NULL, 2);
printf("八进制:%o\n", n);
printf("十进制:%d\n", n);
printf("十六进制:%x\n", n);
return 0;
}
例子:
00010000
八进制:20
十进制:16
十六进制:10
Press any key to continue
#include <stdio.h>
int main(void)
{
int n;
scanf("%d", &n);
printf("八进制:%o\n", n);
printf("十进制:%d\n", n);
printf("十六进制:%x\n", n);
return 0;
}
例子:
16
八进制:20
十进制:16
十六进制:10
Press any key to continue
二:输入二进制,输出八、十、十六进制
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main(void)
{
char string[128];
long n;
scanf("%s", string);
n = strtol(string, NULL, 2);
printf("八进制:%o\n", n);
printf("十进制:%d\n", n);
printf("十六进制:%x\n", n);
return 0;
}
例子:
00010000
八进制:20
十进制:16
十六进制:10
Press any key to continue
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
先用scanf("%d",a)输入a为十进制
再用printf("&x",a)输出,%x为十六进制,%o为八进制
再用printf("&x",a)输出,%x为十六进制,%o为八进制
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include "stdio.h"
main()
{int num;
printf("Input a number please:\n");
scanf("%d",&num);
printf("The num in 16 type is %h",num);
}
main()
{int num;
printf("Input a number please:\n");
scanf("%d",&num);
printf("The num in 16 type is %h",num);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
/*
name : deny
date : 2010/4/2
function : exchange the number you want change
*/
#include <stdio.h>
void Binary_date (int num,int change_num); /*function prototype of Binary_date(int,int)*/
void Binary_exchange (int number,int x);
int main (void)
{
int li_number;
int li_change_num;
printf("please enter a number you want to exchange and enter a change numebr(q to quit):");
while (scanf("%d%d",&li_number,&li_change_num))
{
while (getchar () != '\n');
printf("the number %d is :",li_number);
Binary_date (li_number,li_change_num); /*call the function of Binary_date (int,int)*/
printf("\n");
printf("please enter a number you want to exchange and enter a change numebr(q to quit):");
}
return 0;
}
void Binary_date (int num,int change_num) /*the function of changing the number to binary,octal,hexdecimal number*/
{
int li_temp,li_changed;
li_temp = num / change_num; /*calcualte the diviece*/
li_changed = num % change_num + '0'; /*calculate the mode*/
if(li_temp >= 1)
Binary_date (li_temp,change_num); /*return to call the "himeself"*/
if (li_changed > '9') /*if the changed number beyond character '9',change it to 'A','B','C'....*/
li_changed += 7;
printf("%c",li_changed); /*printting the character*/
}
/*exchange the decimal number*/
void Binary_exchange (int number,int x)
{
SeqStack ls_temp;
int li_temp = number,r;
int i;
InitSeqStack (&ls_temp);
while (li_temp > 0)
{
r = li_temp%x + '0';
if (r >'9')
r += 7; /*ASCII's exchange*/
Push (&ls_temp,r);
li_temp /= x;
}
i = ls_temp.top;
printf("number %d is : ",number);
while (i >= 0)
printf("%c",ls_temp.num[i--]); /*move the index,and printing the date*/
putchar (10);
}
一个函数是基于递归写的,一个是基于栈调用写的,不知道能否帮到你
name : deny
date : 2010/4/2
function : exchange the number you want change
*/
#include <stdio.h>
void Binary_date (int num,int change_num); /*function prototype of Binary_date(int,int)*/
void Binary_exchange (int number,int x);
int main (void)
{
int li_number;
int li_change_num;
printf("please enter a number you want to exchange and enter a change numebr(q to quit):");
while (scanf("%d%d",&li_number,&li_change_num))
{
while (getchar () != '\n');
printf("the number %d is :",li_number);
Binary_date (li_number,li_change_num); /*call the function of Binary_date (int,int)*/
printf("\n");
printf("please enter a number you want to exchange and enter a change numebr(q to quit):");
}
return 0;
}
void Binary_date (int num,int change_num) /*the function of changing the number to binary,octal,hexdecimal number*/
{
int li_temp,li_changed;
li_temp = num / change_num; /*calcualte the diviece*/
li_changed = num % change_num + '0'; /*calculate the mode*/
if(li_temp >= 1)
Binary_date (li_temp,change_num); /*return to call the "himeself"*/
if (li_changed > '9') /*if the changed number beyond character '9',change it to 'A','B','C'....*/
li_changed += 7;
printf("%c",li_changed); /*printting the character*/
}
/*exchange the decimal number*/
void Binary_exchange (int number,int x)
{
SeqStack ls_temp;
int li_temp = number,r;
int i;
InitSeqStack (&ls_temp);
while (li_temp > 0)
{
r = li_temp%x + '0';
if (r >'9')
r += 7; /*ASCII's exchange*/
Push (&ls_temp,r);
li_temp /= x;
}
i = ls_temp.top;
printf("number %d is : ",number);
while (i >= 0)
printf("%c",ls_temp.num[i--]); /*move the index,and printing the date*/
putchar (10);
}
一个函数是基于递归写的,一个是基于栈调用写的,不知道能否帮到你
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
int
main()
{
long
i,j,k;
k=10;
for
(i=1;i<=99;i++)
{
if
(i==k)
k*=10;
j=i*i;
if(j%k==i)
printf("%ld\t%ld\n",i,j);
}
}
int
main()
{
long
i,j,k;
k=10;
for
(i=1;i<=99;i++)
{
if
(i==k)
k*=10;
j=i*i;
if(j%k==i)
printf("%ld\t%ld\n",i,j);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询