me and friend wrote this small prog but it is still not good enugh (it is really long)

could you plz take a look and give me some editions ?
The prog need to take a number then test  :
find the largest digit.
is the number simatric
show the reverse number

it is released under FAL licence ([EMAIL PROTECTED] all licences)
all right belong  to Debian .. :-)

------------------------------------------------------------------------

#include <stdio.h>
#include <string.h>

char get_max_digit(int num);
int get_summ_digits(int num);
char is_symmetric(int num);
int reverse_num(int num);

void menu()
{
        printf("\n1. Summ of digits.\n");
        printf("2. Max digit.\n");
        printf("3. Reverse number.\n");
        printf("4. Is symmetric.\n");
        printf("5. New number.\n");
        printf("6. Exit.\n");
}

int main(int argc, char **argv)
{
        char w = 1;
        int num = 0;

        while (w)
        {
                menu();
                while(isspace(w = getchar()));

                switch(w)
                {
                case '1':
                        printf("Summ of digits is: %i\n", get_summ_digits(num));
                        break;
                case '2':
                        printf("Max. digit is: %i\n", get_max_digit(num));
                        break;
                case '3':
                        printf("Reversed number is: %d\n", reverse_num(num));
                        break;
                case '4':
                        printf("Is symmetric: %d\n", is_symmetric(num));
                        break;
                case '5':
                        printf("Enter new number: ");
                        scanf("%i", &num);
                        break;
                case '6':
                        w = 0;
                        break;
                }
        }
        return 0;
}

char get_max_digit(int num)
{
        char res = num % 10;
        char dig;

        while (num /= 10)
        {
                dig = num % 10;
                if (dig > res)
                        res = dig;
        }

        return res;
}

int get_summ_digits(int num)
{
        int res = num % 10;

        while (num /= 10)
                res += num % 10;

        return res;
}

int reverse_num(int num)
{
        int res = 0;
        int multiplier = 10;

        while (num / multiplier)
                multiplier *= 10;
        multiplier /= 10;

        while(num / 10)
        {
                res += num % 10 * multiplier;
                multiplier /= 10;
                num /= 10;
        }
        res += num;

        return res;
}

char is_symmetric(int num)
{
        char dig1, dig2, res = 0;
        int multiplier1, multiplier2;

        multiplier1 = 1;
        multiplier2 = 10;

        while (num / multiplier2)
                multiplier2 *= 10;
        multiplier2 /= 10;
        
        while(
             (((num / multiplier1) % 10) == ((num / multiplier2) % 10)) &&
              (multiplier1 <= multiplier2)
             )
        {
                multiplier1 *= 10;
                multiplier2 /= 10;
        }

        return (multiplier1 <= multiplier2) ? 0 : 1;
}



--
To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to