Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Jürgen Hein
/
iax0583
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
c3c7a5db
authored
Sep 26, 2024
by
Jürgen Hein
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
20dd0417
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
106 additions
and
0 deletions
Tunnitöö 26.09.24/ArvuAlusteTeisendamine.c
Tunnitöö 26.09.24/ArvuAlusteTeisendamine.c
0 → 100644
View file @
c3c7a5db
//Arvu aluste teisendamine
//Arvu aluste teisendamine
#include <stdio.h>
#include <string.h>
#define SUURUS 65
int
main
(
void
)
{
int
letters
[
7
]
=
{
1
,
4
,
7
,
8
,
9
,
22
,
15
};
char
temp
[
SUURUS
];
char
arv
[
SUURUS
];
int
a
;
int
b
;
int
t
;
int
i
;
int
algbase
;
char
*
alg
;
int
l6ppbase
;
char
*
l6pp
;
int
result
;
int
mult
;
scanf
(
"%s64"
,
arv
);
//tähemassiivi küsimine
/*do
{
printf("Sisestada muutuja arv");
scanf("%d", &arv);
} while (arv != 0);*/
do
{
printf
(
"Sisestada muutuja a"
);
//algbase küsimine
scanf
(
"%d"
,
&
a
);
}
while
(
a
==
0
);
do
{
printf
(
"Sisestada muutuja b"
);
//Lõppbase küsimine
scanf
(
"%d"
,
&
b
);
}
while
(
b
==
0
);
algbase
=
a
;
alg
=&
(
arv
[
0
]);
l6ppbase
=
b
;
l6pp
=&
(
temp
[
0
]);
result
=
0
;
mult
=
1
;
if
(
algbase
<
2
||
algbase
>
36
)
{
printf
(
"Esinese viga!"
);
}
if
(
l6ppbase
<
2
||
l6ppbase
>
36
)
{
printf
(
"Esinese viga!"
);
}
if
(
algbase
==
l6ppbase
)
{
i
=
0
;
while
(
i
<
7
)
//mis n väärtus?
{
alg
[
i
]
=
l6pp
[
i
];
i
++
;
}
}
t
=
strlen
(
alg
);
//t = mitu arvu massiivis alg
i
=
t
-
1
;
for
(
i
=
0
;
i
>=
0
;
i
--
)
//tsükkel kas i>=0?
{
if
(
'0'
<=
alg
[
i
]
||
alg
[
i
]
<=
'9'
)
//Kas massiivi liige on arv vahemikus 0..9?
{
t
=
alg
[
i
]
-
'0'
;
}
if
(
'A'
<=
alg
[
i
]
||
alg
[
i
]
<=
'Z'
){
//Kas massiivi l. on täht vahemikus A..Z?
t
=
alg
[
i
]
-
'A'
+
10
;
}
if
(
'a'
<=
alg
[
i
]
||
alg
[
i
]
<=
'z'
){
//Kas massiivi l. on täht vahemikus a..z?
t
=
alg
[
i
]
-
'a'
+
10
;
}
if
(
t
==-
1
||
t
>=
algbase
)
//t ei saa olla -1 ega väiksem a-st
{
printf
(
"Esinese viga!"
);
}
result
=
result
+
mult
*
t
;
mult
=
mult
*
algbase
;
}
for
(
i
=
0
;
result
>
0
;
i
++
)
{
temp
[
i
]
=
letters
[
result
%
l6ppbase
];
result
/=
l6ppbase
;
//jagada result/lõppbase ja liita tulemus result-ile
}
for
(
t
=
0
;
t
<
1
;
t
++
)
{
l6pp
[
t
]
=
temp
[
i
-
t
-
1
];
}
l6pp
[
i
]
=
'\0'
;
if
(
i
==
0
)
{
l6pp
[
0
]
=
'0'
;
l6pp
[
1
]
=
'\0'
;
}
else
{
printf
(
"arv_a=temp_b"
);
}
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment