Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //zadanie liczba hex do 10
- #include<iostream>
- #include<conio.h>
- #include<cstring>
- using namespace std;
- int potega(int liczba , int potega )
- {
- int wynik1 = liczba;
- if(potega==0) wynik1=1;
- else
- {
- for(int i=1;i<potega;i++)
- {
- wynik1 = wynik1 * liczba;
- }
- }
- return wynik1;
- }
- int main()
- {
- string liczba;
- int wynik,a;
- wynik=0;
- getline(cin,liczba);
- a=liczba.length();
- int b=a-1;
- for(int i=0;i<a;i++)
- {
- if (liczba[b-i]=='A')
- wynik=wynik+(10*potega(16,i));
- else
- if(liczba[b-i]=='B')
- wynik=wynik+(11*potega(16,i));
- else
- if(liczba[b-i]=='C')
- wynik=wynik+(12*potega(16,i));
- else
- cout<<"niepoprawna liczba\n";
- }
- cout<<"\nw systemie dziesietnym jest to: "<<wynik;
- getch();
- return 0;
- }
Add Comment
Please, Sign In to add comment