用C语言编程,输入一个十进制正整数,输出其对应的十六进制整数。
来源:百度知道 编辑:UC知道 时间:2024/05/30 03:31:30
#include<stdio.h>
#include<stdlib.h>
void main(){
int a;
char b[10];
scanf("%d",&a);
itoa(a,b,16);
printf("%s",b);
}
运行结果
a=1000
a=3e8h
Press any key to continue
程序
//VC6.0
#include "stdio.h"
void main()
{
int a;
printf("a=");
scanf("%d",&a);
printf("\na=%xh\n",a);
}
不用系统的函数,用栈实现
// test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <malloc.h>
struct stack
{
char* base;
char* top;
int length;
};
void InitStack(struct stack *p)
{
p->base=(char*)malloc(100);
p->top=p->base;
*(p->top)=0;
p->length=0;
}
bool push(struct stack *p,char a)<