-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab2.2.cpp
More file actions
65 lines (50 loc) · 1.11 KB
/
Lab2.2.cpp
File metadata and controls
65 lines (50 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//convert.cpp
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int conv, base, n, i, curr, pureN, pure, a[40], temp, b[40], t;
pureN = 0;
conv = 0;
cout << "Enter the Number you want to convert :" << endl;
cin >> n;
cout << "Enter the Number the current base of number :" << endl;
cin >> curr;
cout << "Write the Number base that should be converted :" << endl;
cin >> base;
conv = n;
for (i = 0; i<40; i++)
{
a[i] = conv % 10;
conv = conv / 10;
}
/*for (i = i-1; i > -1; i--)
{
cout << a[i];
}*/
for (i = 0; i < 40 ; i++)
{
pure = a[i] * pow(curr,i);
pureN = pureN + pure;
}
temp = pureN;
int j = 0;
while (temp > base)
{
t = temp / base;
b[j] = temp % base;
j = j + 1;
if (t < base)
{
b[j] = t;
}
temp = t;
}
cout << endl << endl;
cout << "The CONVERTED NUMBER IS : ";
for (j;j>-1;j--)
{
cout << b[j];
}
}