#include<stdio.h>
#include<conio.h>

#define MAX 5

void initialize(int a[], int n);
void display (int a[], int n);
void input (int a[], int n);
int sum (int a[], int n);
int largest (int a[], int n);
int smallest (int a[], int n);

void main (void)
{
    int array [MAX];
    int total;
    initialize(array, MAX);
    /*input (array, MAX);
    total=sum(array, MAX);*/
    display (array, MAX);
    printf("total = %d\n", total);
}

void initialize(int a[], int n)
{

}

void display (int a[], int n)
{
    int x;
    printf("Enter a number: %d\n");
    scanf("")
    printf("Enter a number: ");
}

void input (int a [], int n)
{

}

int sum (int a[], int n)
{

}

int largest (int a[], int n)
{

}

int smallest (int a[], int n)
{

}

void comparePaste (int a[], int b[], int c[], int n)
{

}




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

the problem is this: write a program that will ask and store 20 or 10 integers, then compute and display the largest and the smallest value plus the sum among the elements of the array.

guys, do you have any suggestions or ideas about the ff:

function calls or prototypes of

sum
input
largest
smallest
comparePaste
initialize

... or any add - ons about the issues ?

THANKS and GOD BLESS!! :)

First the morale and then the solution:
Even though these things you need to code may seem complicated at first, they are only the beginning :). If you plan on becoming a programmer, you should try to code them yourself. If you only need these things for a better grade... just copy paste "stuff" bellow and live happily ever after..

initialize() function:
Solution 1:

// This function initializes the values in the array a with 0
void initialize(int a[], int n)
{
    for(int index = 0; index < n; index++){
        a[index] = 0;
    }
}

Solution 2:

void initialize(int a[], int n)
{
    memset(a, 0, sizeof(int) * n);
}

display() function:

// This function displays on screen the elements in array a
void display (int a[], int n)
{
    printf("Array elements: \n")
    for(int index = 0; index < n; index++){
        printf("%d ", a[index]);
    }
    printf("\n");
}

input() function:

void input (int a [], int n)
{
    for(int index = 0; index < n; index++){
        // Remove the "+ 1" if you believe that arrays start at index 0 :)
        printf("Set element %d: ", index + 1);
        scanf("%d", &(a[index]));
        fflush(stdin);
    }
}

sum function:

int sum (int a[], int n)
{
    int result = 0;

    for(int index = 0; index < n; index++){
        result += a[index];
    }

    return result;
}

largest() function:
Solution 1:

int largest (int a[], int n)
{
    int result = 0;

    if(n > 0)
        result = a[0];
    for(int index = 1; index < n; index++){
        if(result < a[index]){
            result = a[index];
        }
    }

    return result;
}:

Solution 2:

int largest (int a[], int n)
{
    int result = 0;

    if(n > 0)
        result = a[0];

    for(int index = 1; index < n; index++){
        result = (result < a[index]) ? a[index] : result;
    }

    return result;
}:

smallest() function:
Solution 1:

int smallest (int a[], int n)
{
    int result = 0;

    if(n > 0)
        result = a[0];
    for(int index = 1; index < n; index++){
        if(result > a[index]){
            result = a[index];
        }
    }

    return result;
}:

Solution 2:

int smallest (int a[], int n)
{
    int result = 0;

    if(n > 0)
        result = a[0];

    for(int index = 1; index < n; index++){
        result = (result > a[index]) ? a[index] : result;
    }

    return result;
}:

The last function, comparePaste()... what is it supposed to do?

Last part, the main function. If you want to use instead of 5, 10 or 20 elements, you can redefine MAX as being 10 or 20. However if you want to read from the user the number of elements that he/she wants to store in the array the main function must be rewritten as follows:

#ifndef NULL
#define NULL    (void*)0
#endif // NULL

int main (void)
{
    int arraySize = MAX;
    int* array = NULL;
    int total = 0;

start:
    printf("Set array element count: ");
    scanf("%d", &arraySize);
    if(arraySize <= 0){
        printf("The array element count cannot be less than or equal to zero!\n");
        goto start;
    }

    array = malloc(sizeof(int) * arraySize);
    if(array == NULL){
        printf("Memory allocation failed!");
        return -1;
    }

    initialize(array, arraySize);
    input (array, arraySize);
    total = sum(array, arraySize);
    display (array, arraySize);
    printf("total = %d\n", total);

    if(array){
        free(array);
        array = NULL;
    }

    return 0;
}

P.S.: I wrote the code directly here so I didn't test it. If it has some errors, they are most likely syntax errors.

commented: Do you think doing his homework makes you look smart or something? -5
commented: Don't do this. -1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.