求解一道简单的C语言题

编一个程序,输入一个十进制数,输出相应的十六进制数或者输入二进制输出八进制……总之就是这一类的题怎么做啦~~... 编一个程序,输入一个十进制数,输出相应的十六进制数
或者输入二进制输出八进制……总之就是这一类的题怎么做啦~~
展开
 我来答
raef_beyond
2010-07-06 · TA获得超过1651个赞
知道小有建树答主
回答量:382
采纳率:50%
帮助的人:273万
展开全部
一:输入十进制,输出八、十、十六进制。

#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
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
aboutyty
2010-07-05 · TA获得超过566个赞
知道答主
回答量:321
采纳率:0%
帮助的人:297万
展开全部
先用scanf("%d",a)输入a为十进制
再用printf("&x",a)输出,%x为十六进制,%o为八进制
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
505962973
2010-07-06 · TA获得超过153个赞
知道答主
回答量:59
采纳率:0%
帮助的人:0
展开全部
#include "stdio.h"
main()
{int num;
printf("Input a number please:\n");
scanf("%d",&num);
printf("The num in 16 type is %h",num);
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友960b5b4
2010-07-06
知道答主
回答量:14
采纳率:0%
帮助的人:2.2万
展开全部
/*
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);

}

一个函数是基于递归写的,一个是基于栈调用写的,不知道能否帮到你
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
创作者NiBOn5i5m6
2020-06-10 · TA获得超过3834个赞
知道大有可为答主
回答量:3066
采纳率:29%
帮助的人:193万
展开全部
#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);
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(3)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式