# include <iostream.h>
# include <conio.h>
int LenNum (int num);
int SelNum (int num,int sel);
int Sqr (int num,int tavan);
int ConToTen (int num,int mabna);
int ConFromTen (int num,int mabna);
void main()
{
clrscr();
int num,mabna1,mabna2;
cout << "Please Enter Your Number With Mabna :
";
cin>>num>>mabna1;
cout<<"Please Your Want Mabna :
";
cin>>mabna2;
cout << "Your Number Is "<< num << "("<<mabna1<<")
"
<<"Result Is : "<< ConFromTen(ConToTen(num,mabna1),mabna2)<<"("
<<mabna2<<")";
getch();
}
//*********************************Len Num Function**************************
int LenNum (int num)
{
int count=0;
while (num)
{
num=num/10;
count++;
}
return count;
}
//*********************************Sel Num Function**************************
int SelNum (int num,int sel)
{
int count=0;
if (LenNum(num)>=sel)
{
while (num)
{
count++;
if (count == sel)
return (num % 10);
num=num/10;
}
}
else
{
sel=LenNum(num);
return (SelNum(num,sel));
}
}
//*********************************Sqr Function******************************
int Sqr (int num,int tavan)
{
int result=1;
if (tavan==0)
return 1;
for (int count = 1; count <= tavan ; count++)
result *=num;
return result;
}
//***********************Convert To Ten Function*****************************
int ConToTen (int num,int mabna)
{
int sum=0,sqrnum=0;
for (int count = 1; count<= LenNum(num);count++)
{
if ((SelNum(num,count))==mabna)
{
cout << "Your Number Or Mabna Is Invalid !";
return 0;
}
sum += SelNum(num,count) * Sqr(mabna,sqrnum);
sqrnum++;
}
return sum;
}
//*********************Convert From Ten Function*****************************
int ConFromTen (int num,int mabna)
{
int result=0,tencount=1,test=1;
while (test)
{
result += (num % mabna) * tencount;
num=num/mabna;
tencount*=10;
if (num<mabna)
{
result += num * tencount;
return result;
test=0;
}
}
return result;
}
بازاریابی برای صاحبان وبلاگ و سایت!
دوست عزیز موفق باشی یه سر بزن به وبلاگ من. موافقی تبادل لینک www.engarash.mihanblog.com