Answer to Question #217312 in Python for adhichinna

Question #217312
Numbers To Words Problem

Program to convert a given number to Dollar format
Write code to convert a given number into dollar format. For example, if “1234567” is
given as input, the output should be “one million two hundred thirty-four thousand
five hundred sixty-seven dollars”. Code should be able to provide output up to 1
billion.
1
Expert's answer
2021-07-15T01:53:35-0400
#include <math.h>
#include <stdio.h>
#include <stdlib.h>


int main(int argc, char* argv[]) {


    int i, j;
    int size;
    int* values;
    int min_difference;
    int first_number;
    int second_number;


    scanf("%d", &size);
    if (size > 0)
    {
        values = (int*)malloc(sizeof(int)* (size + 1));
        for (i = 0; i < size; i++)
            scanf("%d", &values[i]);




        if (size > 1)
        {
            min_difference = abs(values[0] - values[1]);
            first_number = values[0];
            second_number = values[1];


            for (i = 0; i < size - 1; i++)
            for (j = i + 1; j < size; j++)
            if (min_difference > abs(values[i] - values[j]))
            {
                min_difference = abs(values[i] - values[j]);
                first_number = values[i];
                second_number = values[j];
            }


            printf("%d %d\n", first_number, second_number);
        }


        free(values);
    }


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS