Old Russian measure of length: Difference between revisions

Added C implementation.
(Add Julia language)
(Added C implementation.)
Line 85:
versta 7.
milia 1.
</pre>
=={{header|C}}==
Accepts length and unit as input, prints out length in all other units. Usage printed on incorrect invocation.
<lang C>
/*Abhishek Ghosh, 25th October 2017*/
 
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
#include<stdio.h>
 
#define UNITS_LENGTH 13
 
int main(int argC,char* argV[])
{
int i,reference;
char *units[UNITS_LENGTH] = {"kilometer","meter","centimeter","tochka","liniya","diuym","vershok","piad","fut","arshin","sazhen","versta","milia"};
double factor, values[UNITS_LENGTH] = {1000.0,1.0,0.01,0.000254,0.00254,0.0254,0.04445,0.1778,0.3048,0.7112,2.1336,1066.8,7467.6};
if(argC!=3)
printf("Usage : %s followed by length as <value> <unit>");
else{
for(i=0;argV[2][i]!=00;i++)
argV[2][i] = tolower(argV[2][i]);
for(i=0;i<UNITS_LENGTH;i++){
if(strstr(argV[2],units[i])!=NULL){
reference = i;
factor = atof(argV[1])*values[i];
break;
}
}
printf("%s %s is equal in length to : \n",argV[1],argV[2]);
for(i=0;i<UNITS_LENGTH;i++){
if(i!=reference)
printf("\n%lf %s",factor/values[i],units[i]);
}
}
return 0;
}
</lang>
Output :
<pre>
C:\rosettaCode>metricRussian.exe 1 meter
1 meter is equal in length to :
 
0.001000 kilometer
100.000000 centimeter
3937.007874 tochka
393.700787 liniya
39.370079 diuym
22.497188 vershok
5.624297 piad
3.280840 fut
1.406074 arshin
0.468691 sazhen
0.000937 versta
0.000134 milia
C:\rosettaCode>metricRussian.exe 3 arshin
3 arshin is equal in length to :
 
0.002134 kilometer
2.133600 meter
213.360000 centimeter
8400.000000 tochka
840.000000 liniya
84.000000 diuym
48.000000 vershok
12.000000 piad
7.000000 fut
1.000000 sazhen
0.002000 versta
0.000286 milia
</pre>
=={{header|C++}}==
503

edits