Predmet:Konvert Oktalni u decimalni
PreuzmiIzvorni kôd (C++):#include<iostream>
int main()
{
using namespace std;
int i,OctNum,DecNum = 0,arr[20];
cout<<"Octal Number to Decimal Number converter."<< endl<<endl;
cout<< "Enter the Number: ";
cin>>OctNum;
for(i=0; OctNum>0; i++) //Save the individual digits of the Octal number to the array.
{
arr[i] = OctNum % 10;
OctNum = OctNum / 10;
}
cout<<i;
//first digit(in ones place) x (8 raise to 0)+2nd digit(tens) x (8 raise to 1) +...+last digit x (8 raise to n-1) where 'n' is the number of digits
for(int power=0, j=0; j<i ; j++,power++)
{
DecNum = DecNum + arr[j] * pow(8.0,power);
}
cout<<"The Decimal form is "<<DecNum;
cin.get();
return 0;
}
Podrska samo putem foruma, jer samo tako i ostali imaju koristi od toga.