1
This is a code whose goal is to add all the integers between a and b. Being "a" less than "b". The expected output was a number representing this sum, however, after reading a and b, nothing happens.
#include <stdio.h>
int soma(int n1,int n2)
{
int i,s;
for(i;n2-1;i++)
s=s+i;
}
return s;
}
int main()
{
int a,b,s;
printf("Digite dois numeros:");
scanf("%d %d",&a,&b);
s=soma(a,b);
printf("Soma=%d",s);
return 0;
}
What is the initial value of variable i in your command for? Wouldn’t it be: for (i=n1; i<=N2; i++)? Also the variable s should be initialized with zero.
– anonimo