# Thread: "Inclusive" problem with my program.

1. ## "Inclusive" problem with my program.

Hey guys, I wrote a program for our assignment, and I'm having only one problem with it. The program is supposed to ask for an integer, find integers divisible by 5 between 1 and the integer you gave, list them, and give the count. My program does this, but for some reason it wont include the number you input.
Like for example, I input the number 20, and the output gives:

Enter a positive integer: 20
15
10
5
0
the count is 4
It wont include the number given, and its not supposed to count '0'. Here's my program:

Code:
```#include <stdio.h>

int main(void)
{
int n;
int count = 0;

printf("Enter a positive integer: ");
scanf("%d", &n);
{
for(n>1; n-- ;)
if(n%5 == 0){
printf("%d\n", n);
count++;}
printf("The count is %d\n", count);

}

}```
What am I doing wrong?

2. add another condition with n>=5.
So this will not include 0 now.
the corrected code is given below

Code:
```int main(void)
{
int n;
int count = 0;

printf("Enter a positive integer: ");
scanf("%d", &n);
{
for(n>1; n-- ;)
if(n%5 == 0 && n>= 5 ){
printf("%d\n", n);
count++;}
printf("The count is %d\n", count);

}

}```
Enter a positive integer: 20
15
10
5
The count is 3

Now the output will be as shown above

3. If you indented your code, you'd see some of the problems:

Code:
```{
for(i = 1, count = 0; i <=n ; i++) {
if((i%5 == 0) && (i)) {
count++;
printf("\n Count is: %d Number Found: %d", count, i);
}
}```
Try that.

Edit: Whoops! See program, below

4. ## Re: "Inclusive" problem with my program.

I think you are doing wrong in that for loop. I changed that.
And If you want to include the 0 also you can use the condition as n>=0 in the for loop.
Try this code

Code:
```#include <stdio.h>

int main(void)
{
int n;
int count = 0;

printf("Enter a positive integer: ");
scanf("%d", &n);
{
for(;n>1; n-- )
if(n%5 == 0){
printf("%d\n", n);
count++;
}
printf("The count is %d\n", count);
}
}```

5. Thought it is a better solution
Code:
```#include <stdio.h>

int main(void)
{
int n;
int count = 0;

printf("Enter a positive integer: ");
scanf("%d", &n);
{
for(n>1; --n ;)
if(n%5 == 0){
printf("%d\n", n);
count++;}
printf("The count is %d\n", count);

}

}```

6. Ok, I see where I didnt add in the extra condition in my IF statement to get rid of the 0's. But I'm having problems with the program including 20 with the solutions.
@Adak, I tried that and it didnt seem to work.
@thillai_selvan, thanks that helped a lot.

I'm wondering if my program is going on about this backwards. Would it include 20 if it worked its way up from 1 to the inputted number? I think my program is working down to 1, so its not going to include 20.

7. Welcome jaja... According to your query I made a little changes. Hope this will solve your requirement completely.

Code:
```int main(void)
{
int n;
int count = 0;

printf("Enter a positive integer: ");
scanf("%d", &n);
{
for(;n>1; n--)
if(n%5 == 0 && n>= 5 ){
printf("%d\n", n);
count++;}
printf("The count is %d\n", count);

}

}```
Try this code. Now this will include your input number also

8. Code:
```#include <stdio.h>

int main(void) {
int i, n, count;

printf("\n\n Enter a number: ");
scanf("%d", &n);
getchar();

for(i = 1, count = 0; i <=n ; i++) {
if((i%5 == 0) && (i)) {
count++;
printf("\n Count is: %d Number Found: %d", count, i);
}
}