/*convert all integer into any base */
#include<stdio.h>
#include<conio.h>
void convert(int,int);
void main()
{
int num,base;
clrscr();
printf("Enter a integer :");
scanf("%d",&num);
printf("\nEnter base :");
scanf("%d",&base);
convert(num,base);
getch();
}
void convert(int num, int base)
{
int rem=num%base;
if(num==0)
return ;
convert(num/base ,base);
if(rem<10)
printf("%d",rem);
else
printf("%c",rem-10+'A');
}
#include<stdio.h>
#include<conio.h>
void convert(int,int);
void main()
{
int num,base;
clrscr();
printf("Enter a integer :");
scanf("%d",&num);
printf("\nEnter base :");
scanf("%d",&base);
convert(num,base);
getch();
}
void convert(int num, int base)
{
int rem=num%base;
if(num==0)
return ;
convert(num/base ,base);
if(rem<10)
printf("%d",rem);
else
printf("%c",rem-10+'A');
}
No comments:
Post a Comment