initial checkin from subversion
This commit is contained in:
41
xto10.c
Normal file
41
xto10.c
Normal file
@@ -0,0 +1,41 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
unsigned long base10;
|
||||
int oldbase;
|
||||
char c[100];
|
||||
unsigned long rest,erg;
|
||||
int pos=0;
|
||||
int i;
|
||||
|
||||
int main()
|
||||
{
|
||||
base10=0;
|
||||
oldbase=36;
|
||||
for(i=0;i<100;c[i++]=0);
|
||||
|
||||
printf("Altes Zahlensystem:");
|
||||
scanf("%d",&oldbase);
|
||||
|
||||
printf("Zahl im %der-System:",oldbase);
|
||||
scanf("%s",&c);
|
||||
pos=0;
|
||||
while(c[pos++]);
|
||||
pos--;
|
||||
int len=pos-1;
|
||||
while(pos--)
|
||||
{
|
||||
if(isdigit(c[len-pos]))
|
||||
{
|
||||
base10 = base10 + (unsigned long)( (double)(c[len-pos]-'0') * ( pow( (double)oldbase,(double)pos ) ) ) ;
|
||||
printf("-N-DEBUG: base10:%d, c:%c, pos:%d\n",base10,c[pos],pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
base10 = base10 + (unsigned long)( ((double)(c[len-pos]-'A')+10) * ( pow( (double)oldbase,(double)pos ) ) );
|
||||
printf("-A-DEBUG: base10:%d, c:%c, pos:%d\n",base10,c[pos],pos);
|
||||
}
|
||||
}
|
||||
printf("Zahl im 10er-system:%d\n",base10);
|
||||
}
|
||||
Reference in New Issue
Block a user