cwiczenie

This commit is contained in:
Sebastian Ranoszek 2025-03-03 15:36:05 +01:00
parent 5c08770c7a
commit 2ddcd48b63

View File

@ -0,0 +1,111 @@
#include <iostream>
#include <cmath>
#include <conio.h>
using namespace std;
void sys_szesnastkowy() {
int n,m,i,j,k;
cout << "n = ";
cin >> n;
int *a = new int[n];
m=n;
i=1;
while(m >= 1){
a[i] = m % 16;
m = m / 16;
i++;
}
k=i-1;
for(i = k; i >= 1; i--) {
if(a[i] == 15) cout << "F";
else if(a[i] == 14) cout << "E";
else if(a[i] == 13) cout << "D";
else if(a[i] == 12) cout << "C";
else if(a[i] == 11) cout << "B";
else if(a[i] == 10) cout << "A";
else cout << a[i];
}
cout << endl;
}
void sys_osemkowy() {
int n,m,i,j,k;
cout << "n = ";
cin >> n;
int *a = new int[n];
m=n;
i=1;
while(m >= 1){
a[i] = m % 8;
m = m / 8;
i++;
}
k=i-1;
for(i = k; i >= 1; i--) {
cout << a[i];
}
cout << endl;
}
void sys_binarny() {
int n,m,i,j,k;
cout << "n = ";
cin >> n;
int *a = new int[n];
m=n;
i=1;
while(m >= 1){
a[i] = m % 2;
m = m / 2;
i++;
}
k=i-1;
for(i = k; i >= 1; i--) {
cout << a[i];
}
cout << endl;
}
int main() {
int choice;
cout << "Wybierz system:" << endl;
cout << "(1) - System Szesnastkowy" << endl;
cout << "(2) - System Osemkowy" << endl;
cout << "(3) - System Binarny" << endl;
cin >> choice;
switch(choice) {
case 1:
sys_szesnastkowy();
break;
case 2:
sys_osemkowy();
break;
case 3:
sys_binarny();
break;
default:
break;
}
system("pause");
return 0;
}