Wednesday, 26 December 2012

Any base to Decimal conversion:


Program for Any base to Decimal conversion:

This program shows how to convert a number in any base(it can be 2, 7..)
to decimal number system.The user enters the number and its base and the program converts it to decimal system.
//any base to decimal converting ....

#include<stdio.h>
#include<conio.h>
void main()
{
long signed int inputnumber,inputbase,k,op,s,p;
clrscr();
printf("Enter the number and its base");
scanf("%ld%ld",&inputnumber,&inputbase);
op=0;
k=inputnumber;
p=1;
while(k!=0)
{
s=k%10;
k=k/10;
op=op+s*p;
p=p*inputbase;
}
printf("The number is %ld",op);
getch();
}

and the output is like:

0 Responses to “Any base to Decimal conversion:”

Post a Comment

Recent Comments

All Rights Reserved Assignments on C language