-1
Basically I’m making a function in C that takes two positive integers M and N and returns the sum of even numbers between these numbers.
When I’m about to run, you show up to type in both numbers. Then when I type nothing else appears, it’s like a blank and nothing happens by pressing enter or something like that. Could you tell me what’s wrong with my code?
#include <stdio.h>
void calculo(int m, int n){
int aux = 0, soma = 0, i;
if(n>m){
aux = m;
m = n;
n = aux;
}
for(i = n;n < m;i++){
if(i % 2 == 0){
soma = soma+i;
}
}
printf("O resulado da soma eh igual a: %d", soma);
}
main(){
int x, y;
printf("Digite dois numeros:");
scanf("%d%d", &x, &y);
calculo(x,y);
return 0;
}
I believe that this
for(i = n;n < m;i++){
is under the wrong termination condition. How do you reversen
andm
case(n>m)
thisfor
only case shall be closedn == m
, in other cases will loop .– anonimo