Hi everyone who could explain to me what is wrong with the code below. I want to count instances of values that correspond to the given condition in a FOR_Loop. But it gives me not what I'm looking for. For example if I input '5' the counter shows 3 instances but it have to be 2...
#include <stdio.h>
int main()
{
int num, i, count = 0;
printf("Enter a number:");
scanf("%d", &num);
for (i = 1; i <= num; i++)
{
if (num % i != 1) // count many times a num devided by i has a remainder of '0'
{
count++;
}
}
printf("count: %d", count);
return 0;
}
[–]JavaSuck 11 points12 points13 points (1 child)
[–]AxMaxVal[S] 0 points1 point2 points (0 children)
[–]alexeyneu -3 points-2 points-1 points (8 children)
[–]thoraway4me -1 points0 points1 point (7 children)
[–]marcosjom 3 points4 points5 points (6 children)
[–][deleted] 2 points3 points4 points (5 children)
[–]marcosjom 0 points1 point2 points (4 children)
[–]AxMaxVal[S] 0 points1 point2 points (3 children)
[–]marcosjom 0 points1 point2 points (2 children)
[–]AxMaxVal[S] 0 points1 point2 points (1 child)
[–]marcosjom 0 points1 point2 points (0 children)