I need to write a program that will count how many numbers within an interval have an even sum of digits. you are given two numbers, a and b. i wrote a little program that is a little slow.. it checks for the sum of the digits for every number in the interval. Any suggestions about a better algorithm appreciated.
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
string c;
stringstream ss;
int a,b, rezx, count;
cin>>a>>b;
for(int i=a; i<b; i++)
{
ss<<i;
c=ss.str();
ss.str("");
for(int x=0; x<c.length(); x++)
{
rezx=rezx+c[x];
}
if(rezx%2==0)
{
count++;
}
rezx=0;
}
cout<<count-1;
system("pause");
return 0;
}