Correct answer however uri does not accept

0

I'm starting to study pointer and I decided to change my codes to use pointers, but I tried to send that solution to uri and he gave a message - In queue - I do not know where the error is, why the entries I tried give the solution that the problem asked for.

question link

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int i;
int *vetor(int v[]);

 int main(int argc, char** argv)
{
  int vet[10],*ponte;
  for(i=0;i<10;i++)
{
    scanf("%d",&vet[i]);
}
  ponte=vetor(vet);
    for(i=0;i<10;i++)
    {
        printf("X[%d] = %d\n",i,ponte[i]);
    }
free(ponte);
return 0;
}

int *vetor(int v[])
{
   int *igual=(int*)malloc(sizeof(int)*10);
   for(i=0;i<10;i++)
   {
      if(v[i]<=0)
      {
        igual[i]=1;
      }
      else
      {
        igual[i]=v[i];
      }
}
  return igual;
}
    
asked by anonymous 02.01.2018 / 05:50

1 answer

3

The code looks good - if it works for examples you've done, it should work for any case.

The problem may be that although the statement does not say anything, there may be large numbers that do not fit into a simple 32-bit integer. Try to replace all occurrences of int with long long - this will make your program work with 64bit integers, and may be enough.

Another thing is that the status "in queue" you say is not necessarily an error, but rather that your program is still in the queue to be tested. Are you sure you have an error message? What is it?

And finally, and indeed, most important of this answer, since your code is essentially correct:

Beware of indentation !

It's optional in C, but it's meant for us humans, we can read your code. Your code has no logical flaws and is quite straightforward, but is essentially unreadable by people, because the indentation is almost random.

Choose a simple rule and follow it: be sure to enter an idle level "just because it is the key of a function" - it should not go in column 0. Or put the key on the same line as the block , or place the key in an extra level of indentation.

Likewise, the for command that prints the result is not inside a separate block - it must be in line with the previous line ( ponte = ... ).

It may seem like irrelevant details, but start doing that and see that even for you the code is much easier to follow.

    
02.01.2018 / 14:38