
Untitled
By:
Mohamed_Samy on
May 7th, 2012 | syntax:
None | size: 0.65 KB | hits: 23 | expires: Never
#include <stdio.h>
#include <stdlib.h>
int main()
{
int x,base,n,m,sum=0,origbase,origx;
printf("Welcome to Converting to Decimal Program\n");
printf("Enter your Base [2-10]: ");
scanf("%d",&base);
printf("Enter a number in Base %d: ",base);
scanf("%d",&x);
origbase=base;
origx=x;
while(x>0){
x=x/10;
m=x%10*1;
if(m>=base){
printf("\nInvalid number");
break;
}
else{
n=m*base;
base=base*base;
sum=sum+n;
}
}
sum=sum+origx%10;
printf("%d (base %d) = %d (decimal)",origx,origbase,sum);
return 0;
}