0
a)         Write an algorithm to add and multiply two large integers, which cannot be 
represented by built-in types.
b)         Write a “c” function to find recursively the maximum and minimum element of 
    an array A of size “n” elements. Find also the number of comparisons required for 
this.





a)         Write an algorithm to add and multiply two large integers, which cannot be 
represented by built-in types.
b)         Write a “c” function to find recursively the maximum and minimum element of 
    an array A of size “n” elements. Find also the number of comparisons required for 
this.
2
Contributors
2
Replies
4
Views
4 Years
Discussion Span
Last Post by pestallozi
-2

Example of b

#include <stdio.h>

int Highest (const int l, const int r)
{
    return ((l > r) ? l : r);
}

int Lowest (const int l, const int r)
{
    return ((l < r) ? l : r);
}

void FindMinMax (const int A[], const int n, int* const min, int* const max)
{
    int curMin = 0, curMax = 0;

    if (n == 1)
    {
        (*min) = A[0];
        (*max) = A[0];
    }
    else if (n > 1)
    {
        curMin = A[0];
        curMax = A[0];

        FindMinMax(A + 1, n - 1, min, max);

        (*min) = Lowest ((*min), curMin);
        (*max) = Highest((*max), curMax);
    }
}

int main(void)
{
    int example[] = { 23, 488, 1, 2930, 99, 102 };
    int low, high;

    FindMinMax(example, sizeof(example) / sizeof(int), &low, &high);
    printf("lowest: %d, highest: %d\n", low, high);

    return 0;
}

Found "a" too boring so didn't bother doing that.. Could maybe help if you start on it so I only have to finish/correct it.

Votes + Comments
not even single effort seen , yet you give the code instead of advices
The OP's question falls under our homework rule.
0

Heeee! if you knew whom you are responding to, you wouldn't mind even teaching him 1+1 =2. I am a complete "newbie" to programming, started a few weeks ago. Its only that I am very much interested in grasping these things as much and as fast as I can. I know it takes time to learn, but I try!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.