N
N
nkorobkov2016-02-18 17:23:38
C++ / C#
nkorobkov, 2016-02-18 17:23:38

Why does the program (search for the minimum and maximum in the array) not work?

Here is the program itself. Please do not swear, I'm just starting to learn programming.

int N = 5, A[N], i;
    for(i = 0; i < N; i++){
        printf("Enter A[%d]\n", i);
        scanf("%d", &A[i]);
    }
    printf("\nNumber of element\tValue\n");
    for(i = 0; i < N; i++){
        printf("A[%d]\t\t\t%d\n", i, A[i]);
    }
    int min = A[0], max = A[0];
    for(i = 0; i < N; i++){
        if(A[i] < min) min = A[i];
        if(A[i] > max) max = A[i];
    }
    printf("min = %d\nmax = %d");

Answer the question

In order to leave comments, you need to log in

2 answer(s)
3
3vi1_0n3, 2016-02-18
@nkorobkov

#include <stdio.h>

void main() {
    int N = 5, A[N], i;

    for(i = 0; i < N; i++){
        printf("Enter A[%d]\n", i);
        scanf("%d", &A[i]);
    }

    printf("\nNumber of element\tValue\n");

    for(i = 0; i < N; i++){
        printf("A[%d]\t\t\t%d\n", i, A[i]);
    }

    int min = A[0], max = A[0];

    for(i = 0; i < N; i++){
        if(A[i] < min) min = A[i];
        if(A[i] > max) max = A[i];
    }

    printf("min = %d\nmax = %d\n", min, max);
}

V
Vladimir Martyanov, 2016-02-18
@vilgeforce

Learn to use a debugger.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question