Friday 29 April 2016

Solution of URI 1180 :: Lowest Number and Position


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

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

2 comments:

  1. #include
    int main() {
    int X[1000],i,N,min,position;
    scanf("%d",&N);
    min=X[0];
    for(i=0;i<N;i++){
    scanf("%d",&X[i]);
    min=(X[i]<min)?X[i]:min;
    }
    for(i=0;i<N;i++){
    if(min==X[i]){
    position = i;
    break;
    }
    }
    printf("Menor valor: %d\n",min);
    printf("Posicao: %d\n",position);
    return 0;
    }why geting 5% wrong

    ReplyDelete

Note: only a member of this blog may post a comment.