// DaneEdwards, dedw358.
// Dmitri's tutorial
// Wednesday 26 March
// this is task 1
//it converts a number into old norse, in the output form Number => OldNorseNumber\n, eg 1 => Einn\n
DEFINE
#define HUNDRAO_NUMBER 120
#include <stdio.h>
int under20(int number);
void underHundrao(int digit);
void overHundrao(int digit);
void multipleOfHundrao(int digit);
//This is the main program. It reads in a number, and then prints out that number =>, which is used for every single value
int main (int argc, char* argv[]) {
int number;
scanf("%d", &number);
printf("%d => ", number);
//this is handled here to stop under20 from adding it to the output of non-zero numbers
if (number==0) printf("naught");
//Check if the number is under 20. If it is, then it is a special case which needs to be handled by the under20 function
if (number<=20) under20(number);
//if it is underneath a Hundrao and ten, AND if it is under 20, then it can be handled by the underHundrao function
if (number<=HUNDRAO_NUMBER + 10){
if (number >20){
underHundrao(number);
number -= (number/10 * 10);
if (number !=0){
printf(" ok ");
under20(number);
}
}
//print a newline here, and only here, to satisfy the spec and avoid confusion. Placing this here as opposed to in under20 allows me to reuse under20 for the number of thusandirs
printf("\n");
}
if (number>HUNDRAO_NUMBER+10) overHundrao(number);
return 0;
}
//if a number is over a hundrao, figure out if the part of the number that can't be handled by underHundrao is a multiple of 120
void overHundrao(int digit){
int tens;
tens = (digit/10)*10;
under20(tens/120);
if (digit<130) underHundrao(digit) ;
else{
under20(digit);}
}
//if a number is under a Hundrao, then use this to work out the part that can't be handled by under20, by using the magic of integer division to gain the first digit
void underHundrao(int digit){
while(digit > 13) digit /= 10;
if (digit==2) printf ("tuttugu");
if (digit==3) printf ("thrir tigir");
if (digit==4) printf ("fjogur tigir");
if (digit==5) printf ("fimm tigir");
if (digit==6) printf ("sex tigir");
if (digit==7) printf ("sjau tigir");
if (digit==8) printf ("atta tigir");
if (digit==9) printf ("niu tigir");
if (digit==10) printf ("tiu tigir");
if (digit==11) printf ("ellifu tigir");
if (digit==12) printf ("hundrao");
}
//If a number is under twenty, use this simple routine to handle it
int under20(int number){
if (number==1)printf ("einn");
if (number==2)printf ("tvau");
if (number==3)printf ("thrir");
if (number==4)printf ("fjogur");
if (number==5)printf ("fimm");
if (number==6)printf ("sex");
if (number==7)printf ("sjau");
if (number==8)printf ("atta");
if (number==9)printf ("niu");
if (number==10)printf ("tiu");
if (number==11)printf ("ellifu");
if (number==12)printf ("tolf");
if (number==13)printf ("threttan");
if (number==14)printf ("fjortan");
if (number==15)printf ("fimmtan");
if (number==16)printf ("sextan");
if (number==17)printf ("sjautan");
if (number==18)printf ("atan");
if (number==19)printf ("nitjan");
if (number==20)printf ("tuttugu");
return 0;
}