tuasite Posted January 13, 2008 at 06:58 PM Report Share #159636 Posted January 13, 2008 at 06:58 PM Boas amigos foi me pedido para fazer estes programa: Desenvolva um algoritmo que leia dois numeros inteiros (n1 e n2) e que mostre e que mostre todos os numeros entre n1 e n2 que sejam multiplos de 4. Eu fiz o seguinte codigo mas nao funciona: #include <stdio.h> #include <stdlib.h> int main() { int i,n1,n2,aux; printf("Digite dois numeros:\n"); scanf("%d""%d",&n1,n2); if (n2>n1) { aux=n1; n1=n2; n2=aux; } for (i=n1;i<=n2;i++) if (i%4==0) printf("%d ",i); return 0; } Obrigado amigos Link to comment Share on other sites More sharing options...
Hipnoted Posted January 13, 2008 at 07:05 PM Report Share #159637 Posted January 13, 2008 at 07:05 PM Falta-te o & no segundo número (n2). "Nunca discutas com um idiota. Eles arrastam-te até ao seu nível e depois ganham-te em experiência" Link to comment Share on other sites More sharing options...
Rui Carlos Posted January 13, 2008 at 07:06 PM Report Share #159638 Posted January 13, 2008 at 07:06 PM Coloca o & antes do n2. O if parece-me que tem a condição ao contrário. Rui Carlos Gonçalves Link to comment Share on other sites More sharing options...
xbrunox Posted January 13, 2008 at 07:08 PM Report Share #159639 Posted January 13, 2008 at 07:08 PM No scanf devia estar scanf("%d %d",&n1,&n2); Repara que também existe um problema no interior das aspas. Persistência, persistência, persistência!!linuxfreechoice - Blog com dicas úteis. Link to comment Share on other sites More sharing options...
Rui Carlos Posted January 13, 2008 at 07:10 PM Report Share #159640 Posted January 13, 2008 at 07:10 PM No scanf devia estar scanf("%d %d",&n1,&n2); Repara que também existe um problema no interior das aspas. As aspas não são problema no scanf. É a mesma coisa que ter "%d%d". Rui Carlos Gonçalves Link to comment Share on other sites More sharing options...
tuasite Posted January 13, 2008 at 07:12 PM Author Report Share #159641 Posted January 13, 2008 at 07:12 PM Boas amigos ja fiz a altereção mas mesmo assim nao funciona, obrigado. #include <stdio.h> #include <stdlib.h> int main() { int i,n1,n2,aux; printf("Digite dois numeros:\n"); scanf("%d %d",&n1,&n2); if (n1<n2) { aux=n1; n1=n2; n2=aux; } for (i=n1;i<=n2;i++) if (i%4==0) printf("%d ",i); return 0; } Link to comment Share on other sites More sharing options...
Rui Carlos Posted January 13, 2008 at 07:12 PM Report Share #159642 Posted January 13, 2008 at 07:12 PM Deixaste o if tal como estava... Rui Carlos Gonçalves Link to comment Share on other sites More sharing options...
tuasite Posted January 13, 2008 at 07:15 PM Author Report Share #159643 Posted January 13, 2008 at 07:15 PM Boas amigos alterei o if para if (n1>n2) e ficou logo a funcionar, obrigadíssimo pessoal. Link to comment Share on other sites More sharing options...
MX+ Posted January 16, 2008 at 11:59 PM Report Share #160264 Posted January 16, 2008 at 11:59 PM Ainda podes otimizar mais isso ; ) Quando encontrares o primeiro multiplo de 4, podes incrementar o i de 4 em 4 🙂 Cumprimentos. 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