For starters, you need to indent your code properly:
Code:
#include <stdio.h>
int main()
{
int n,maior,menor;
printf("Digite um numero");
scanf("%d", &n);
maior = n;
menor = n;
printf(" o maior e %d e o menor e %d",maior_menor(n,maior,menor));
return 0;
}
int maior_menor(n,maior,menor)
{
int contador,novo;
contador = 0;
while (contador <= n-1)
{
printf("digite um numero");
scanf( "%d", &novo);
if (novo> maior) maior = novo;
if (novo< menor) menor = novo;
contador = n+1;
}
return maior, menor;
}
Then, you need to compile at a high warning level and pay attention to the warnings:
Code:
test.c: In function ‘main’:
test.c:13:5: warning: implicit declaration of function ‘maior_menor’ [-Wimplicit-function-declaration]
printf(" o maior e %d e o menor e %d",maior_menor(n,maior,menor));
^
test.c:13:5: warning: format ‘%d’ expects a matching ‘int’ argument [-Wformat=]
test.c: In function ‘maior_menor’:
test.c:17:5: warning: type of ‘n’ defaults to ‘int’ [enabled by default]
int maior_menor(n,maior,menor)
^
test.c:17:5: warning: type of ‘maior’ defaults to ‘int’ [enabled by default]
test.c:17:5: warning: type of ‘menor’ defaults to ‘int’ [enabled by default]
test.c:30:17: warning: left-hand operand of comma expression has no effect [-Wunused-value]
return maior, menor;
^
What the warnings are telling you:
- You forgot to forward declare the function maior_menor before calling it in the main function. ("implicit declaration of function ‘maior_menor’")
- You have two %d format specifiers in the printf format string, but only one corresponding argument, i.e., the return value of the call to maior_menor. ("format ‘%d’ expects a matching ‘int’ argument")
- You forgot to declare the types of the parameters of maior_menor. ("type of ‘n’ defaults to ‘int’")