//c code to convert a number in base(2-9) to base 10
#include<stdio.h>
#include<math.h>
#include<conio.h>
int main(){
clrscr();
int base,number,i=0,j,rem,temp;
long sum=0;
printf("enter a number and it's base(2 to 9)\n");
scanf("%d%d",&number,&base);
for(j=number;j>0;j/=10){
rem=j%10;
sum+=rem*pow(base,i);
i++;
}
printf("%d in base 10 is %ld",number,sum);
getch();
return 0;
}
No comments:
Post a Comment