I just recently figured I'd try to learn how to code. I'm at the basics and found some exercises to do online, but I've sat at this for ~40 mins and can't figure it out. So even though this might seem basic to most of you I'll ask for some help :)
So here's the task:
The specified integers are in the range [m, n]. Write a program to find the number with the greatest divisors.
Input / output :
Initial data | Result
10 40 | 36
Code :
#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char *argv[])
{
int m, n, s, sd = 0, ats;
double a = 0;
ifstream fd("Duomenys.txt");
fd >> m >> n;
for(int i = m; i<=n; i++){
s = 0;
for(int j = 1; j<=i; ++j){
a = 0;
a = i % j;
if(a = 0) s= s + 1;
}
if(s > sd) {
i = ats;
s = sd;
}
}
cout << ats;
system("PAUSE");
return EXIT_SUCCESS;
}
Now I'm only using cout << ats
to test it for the moment, but if I run it it gets a 0 as an answer.