2. Counting in Lojban, an artificial language developed
over the last fourty years, is easier than in most languages
The numbers from zero to nine are:
0 no
1 pa
2 re
3 ci
4 vo
5 mk
6 xa
7 ze
8 bi
9 so
Larger numbers are created by gluing the digit togather.
For Examle 123 is pareci
Write a program that reads in a lojban string(representing
a no less than or equal to 1,000,000) and output it in
numbers.

Answer Posted / abdur rab

#include <stdio.h>

int decimal_from_logban ( char* cp_logban )
{
if ( !strcmp ( cp_logban, "no" ) ) return 0;
if ( !strcmp ( cp_logban, "pa" ) ) return 1;
if ( !strcmp ( cp_logban, "re" ) ) return 2;
if ( !strcmp ( cp_logban, "ci" ) ) return 3;
if ( !strcmp ( cp_logban, "vo" ) ) return 4;
if ( !strcmp ( cp_logban, "mk" ) ) return 5;
if ( !strcmp ( cp_logban, "xa" ) ) return 6;
if ( !strcmp ( cp_logban, "ze" ) ) return 7;
if ( !strcmp ( cp_logban, "bi" ) ) return 8;
if ( !strcmp ( cp_logban, "so" ) ) return 9;
}

void logban_2_decimal ( char* _lojban, int* _decimal )
{
char lojban_array [3];

memset ( lojban_array, '\0', 3 );
if ( ( NULL != _lojban ) && ( '\0' != *( _lojban +
2 ) ) ) {
logban_2_decimal ( _lojban + 2, _decimal +
1 );
strncpy ( lojban_array, _lojban, 2 );
*_decimal = decimal_from_logban (
lojban_array );
} else {
strncpy ( lojban_array, _lojban, 2 );
*_decimal = decimal_from_logban (
lojban_array );
}

}

int main ( int argc, char* argv [] )
{
char number_lojban [] = {"sopareci"};
int number_decimal [8];
int i = 0;

logban_2_decimal ( number_lojban, number_decimal ) ;
printf ( "\nLojban :%s", number_lojban );

printf ( "\nDecimal :" );
for ( i = 0; i < ( strlen ( number_lojban ) / 2 );
i++ )
printf ("%d", number_decimal [ i ] );

return ( 0 );
}

Is This Answer Correct ?    2 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

how to build a exercise findig min number of e heap with list imlemented?

1599


How are portions of a program disabled in demo versions?

739


In a byte, what is the maximum decimal number that you can accommodate?

616


What are the string functions? List some string functions available in c.

594


In C language, a variable name cannot contain?

729






Can a variable be both constant and volatile?

551


Write a code to generate divisors of an integer?

626


Is a pointer a kind of array?

589


how to execute a program using if else condition and the output should enter number and the number is odd only...

1646


What do you understand by normalization of pointers?

615


What is volatile, register definition in C

678


I completed my B.tech (IT). Actually I want to develop virtual object that which will change software technology in the future. To develop virtual object what course I have to take. can I any professor to help me.

1730


Explain how do you print an address?

649


What is the use of #define preprocessor in c?

607


Define and explain about ! Operator?

607