Prikazi cijelu temu 24.10.2013 22:23
zxz Na mrezi
Administrator
Registrovan od:03.02.2009
Lokacija:Tuzla


Predmet:Konvert Oktalni u decimalni
PreuzmiIzvorni kôd (C++):
  1. #include<iostream>
  2.  
  3. int main()
  4. {
  5.     using namespace std;
  6.     int i,OctNum,DecNum = 0,arr[20];
  7.    
  8.     cout<<"Octal Number to Decimal Number converter."<< endl<<endl;
  9.    
  10.     cout<< "Enter the Number: ";
  11.     cin>>OctNum;
  12.    
  13.     for(i=0; OctNum>0; i++)    //Save the individual digits of the Octal number to the array.
  14.     {
  15.         arr[i] = OctNum % 10;
  16.         OctNum = OctNum / 10;
  17.     }
  18.     cout<<i;
  19.     //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
  20.     for(int power=0, j=0; j<i ; j++,power++)
  21.     {
  22.         DecNum = DecNum + arr[j] * pow(8.0,power);
  23.     }
  24.    
  25.     cout<<"The Decimal form is "<<DecNum;
  26.  
  27.     cin.get();
  28.     return 0;
  29. }

Podrška samo putem foruma, jer samo tako i ostali imaju koristi od toga.