Friday, November 24, 2017

1180 Lowest Number and Position

                                                  URI Online Judge | 1180

              Lowest Number and Position

                                          Adapted by Neilor Tonin, URI Brazil
Timelimit: 1
Write a program that reads a number N. This N is the size of a array X[N]. Next, read each of the numbers of X, find the smallest element of this array and its position within the array, printing this information.

Input

The first line of input contains one integer N (1 < N <1000), indicating the number of elements that should be read to an array X[N] of integer numbers. The second row contains each of the N values, separated by a space.

Output

The first line displays the message “Menor valor:” followed by a space and the lowest number read in the input. The second line displays the message “Posicao:” followed by a space and the array position in which the lowest number is, remembering that the array starts at the zero position.

Input Sample

10
1 2 3 4 -5 6 7 8 9 10

                                                                               Output Sample 

                                             Menor valor: -5
                                    Posicao: 4

                                                                Solution:

#include<stdio.h>
int main()
{
    int N[1000],i,count=0,X;
    int min=N[count];
    scanf("%d",&X);
    for(i=0;i<X;i++)
    {
        scanf("%d",&N[i]);
    }
    for(i=0;i<X;i++)
    {
        if(N[i]<min)
        {
            min=N[i];
            count=i;
        }
    }
    printf("Menor valor: %d\nPosicao: %d\n",N[count],count);  
    return 0;
}













Featured Post

Increase Your Laptop s Wifi Signal Faster