/* * Task 1 - Esthetic Number * * GUEST LANGUAGE: THIS IS THE C VERSION OF ch-1.pl. */ #include #include #include //#include #include #include #include "args.h" // // bool isesth = is_esthetic( n, msgbuf, bufsize ); // Determine whether n is esthetic, returning the // boolean answer to the question "is it esthetic?", // and using msgbuf (a writable string buf of size bufsize) // to store a printable explanation of why - or why not - // n is esthetic, in the above format. // |5 - 4| = |4 - 5| = |5 - 6| = 1 // or |2 - 0| != 1 // bool is_esthetic( int n, char *msgbuf, int bufsize ) { if( n<10 ) { assert( bufsize>20 ); strcpy( msgbuf, "because no single digit is" ); return 0; } // convert n to string form (for easier access to digits) char dig[100]; sprintf( dig, "%d", n ); int ndig = strlen(dig); // look for any pair of digits not differing by 1 for( int i=0; i20 ); sprintf( msgbuf, "|%c - %c| != 1", a, b ); return 0; } } // ok, all pairs of digits differ by 1.. form msgbuf strcpy( msgbuf, "" ); int mlen = 0; for( int i=0; i