pudim Posted November 6, 2009 at 07:36 PM Report Share #294994 Posted November 6, 2009 at 07:36 PM O problema é o seguinte: Escreva um programa para somar uma sequência de números inteiros. O programa começa por ler qual o número de valores a somar, depois vai lendo os sucessivos valores enquanto faz as contas, e no final escreve o resultado. Aqui está a minha resolução: int main(void) { int n, total = 0, i, v; scanf("%d", &n); for( i=0; i < n; i++) scanf("%d", &v); total += v; printf("%d\n", total); return 0; } Dá os seguintes erros: Compiling source file(s)... I23.c I23.c: In function `main': I23.c:11: warning: control reaches end of non-void function I23.c: At top level: I23.c:12: error: parse error before '{' token IP-B.exe - 1 error(s), 1 warning(s) Se alguém me pudesse esclarecer o significado do erro e me dissesse o que está incorrecto na minha resolução, tendo em conta o enunciado do problema, agradecia 😛 Link to comment Share on other sites More sharing options...
Baderous Posted November 6, 2009 at 09:14 PM Report Share #295003 Posted November 6, 2009 at 09:14 PM Faltam-te as chavetas do for para englobar as 2 instruções que se lhe seguem. Link to comment Share on other sites More sharing options...
pudim Posted November 7, 2009 at 11:06 AM Author Report Share #295026 Posted November 7, 2009 at 11:06 AM obrigado pelo esclarecimento 😛 Link to comment Share on other sites More sharing options...
pudim Posted November 7, 2009 at 11:37 AM Author Report Share #295028 Posted November 7, 2009 at 11:37 AM Já adicionei as chavetas: int main(void) { int n, total = 0, i, v; scanf("%d", &n); for( i=0; i < n; i++) { scanf("%d", &v); total += v; } printf("%d\n", total); return 0; } Dá 0 erros e 2 warnings: --------------------Configuration: IP-B - Debug-------------------- Compiling source file(s)... I23.c I23.c: In function `main': I23.c:4: warning: implicit declaration of function `scanf' I23.c:10: warning: implicit declaration of function `printf' Linking... IP-B.exe - 0 error(s), 2 warning(s) A que se deve estes warnings e o que é que está incorrecto na minha resolução? Se alguém me puder esclarecer agradecia. 😛 Link to comment Share on other sites More sharing options...
n3lThon Posted November 7, 2009 at 12:06 PM Report Share #295029 Posted November 7, 2009 at 12:06 PM Falta-te a biblioteca stdio.h. Coloca antes do int main(void): #include <stdio.h> dreams.each do |dream| dream.make_it_happen end Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now