Wednesday, September 26, 2018

Solution of URI 1180::Lowest Number and Position

Before seeing the solution make sure that you have tried enough. Don’t copy the whole code, just find out the logic. If you feel any problemyou will inform me by comment.




#include <stdio.h>
int main(){
    int N,i,small,p=0;
    scanf("%d",&N);
    int X[N];

    for(i=0;i<N;i++){
        scanf("%d",&X[i]);
    }

    small = X[0];
    for(i=1;i<N;i++){
        if(X[i]<small){
            small = X[i];
            p=i;
        }
    }

    printf("Menor valor: %d\nPosicao: %d\n",small,p);

    return 0;
}

No comments:

Post a Comment