Monday, 7 March 2016

Solution of URI 1080 :: Highest 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 x=0,a,b,c,e,d=0;
    for(a=1;a<=100;a++)
    {
        scanf("%d", &b);
        x++;
        if(b>d)
        {
            e=x;
            d=b;
        }
    }
    printf("%d\n",d);
    printf("%d\n",e);
    return 0;
}

10 comments:

  1. what is the function of writing x=0 and d=0?

    ReplyDelete
    Replies
    1. Initially x and d has a value.
      I need to make sure that there value is zero for the purpose of calculation.

      Delete
  2. can i do it in selection sort mathod?
    #include
    int main()
    {
    int a[100],i,k,j;
    for(i=0;i<100;i++)
    {
    scanf("%d",&a[i]);
    }
    k=a[0];
    j=1;
    for(i=1;i<99;i++)
    {

    if(k<a[i])
    {
    k=a[i];
    j=i+1;
    }
    }
    printf("%d\n%d\n",k,j);
    return 0;
    }
    what is wrong with it?(50% error)

    ReplyDelete
    Replies
    1. #include
      int main()
      {
      int a[1000],i,max,b=0;
      max=a[0];
      for(i=0;i<100;i++){
      scanf("%d",&a[i]);
      if(max<a[i])
      max=a[i];
      b=a[i]+1;
      }
      printf("%d\n",max);
      printf("%d\n",b+1);


      return 0;
      }

      what is wrong with it ?
      25% error

      Delete
  3. How position is stored ?? please explain its algorithm.

    ReplyDelete
  4. I´m really impressed! It helped me a lot! Your solution is short and pretty understandable!!

    ReplyDelete
  5. #include
    int main()
    {
    int a[1000],i,max,b=0;
    max=a[0];
    for(i=0;i<100;i++){
    scanf("%d",&a[i]);
    if(max<a[i])
    max=a[i];
    b=a[i]+1;
    }
    printf("%d\n",max);
    printf("%d\n",b+1);


    return 0;
    }

    why 25% error that one
    !!!!!!!!!!!!!!!!!!

    ReplyDelete
  6. #include
    int main()
    {
    int a[100],i,max,b=0,c;
    max=a[0];

    for(i=0;i<10;i++){
    scanf("%d",&a[i]);
    b++;
    if(max<a[i]){
    max=a[i];
    c=b;

    }


    }
    printf("%d\n",max);
    printf("%d\n",c);


    return 0;
    }

    100% right ans
    boss raheeeeeeeeeeeeeeeeeeeeee

    ReplyDelete

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