Commit c3c7a5db by Jürgen Hein

Upload New File

parent 20dd0417
Showing with 106 additions and 0 deletions
//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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment