Guest User

Untitled

a guest
Jul 17th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. //zadanie liczba hex do 10
  2. #include<iostream>
  3. #include<conio.h>
  4. #include<cstring>
  5.  
  6. using namespace std;
  7.  
  8. int potega(int liczba , int potega )
  9. {
  10. int wynik1 = liczba;
  11. if(potega==0) wynik1=1;
  12. else
  13. {
  14. for(int i=1;i<potega;i++)
  15. {
  16. wynik1 = wynik1 * liczba;
  17. }
  18. }
  19. return wynik1;
  20. }
  21.  
  22. int main()
  23. {
  24. string liczba;
  25. int wynik,a;
  26. wynik=0;
  27.  
  28. getline(cin,liczba);
  29. a=liczba.length();
  30. int b=a-1;
  31. for(int i=0;i<a;i++)
  32. {
  33. if (liczba[b-i]=='A')
  34. wynik=wynik+(10*potega(16,i));
  35. else
  36. if(liczba[b-i]=='B')
  37. wynik=wynik+(11*potega(16,i));
  38. else
  39. if(liczba[b-i]=='C')
  40. wynik=wynik+(12*potega(16,i));
  41. else
  42. cout<<"niepoprawna liczba\n";
  43.  
  44.  
  45. }
  46.  
  47.  
  48. cout<<"\nw systemie dziesietnym jest to: "<<wynik;
  49. getch();
  50. return 0;
  51. }
Add Comment
Please, Sign In to add comment