Write a c program to find all numbers divisible by 5 between a range also calculate their sum




In this c program we need to find all numbers that are divisible by 5 means when we take mod of a number by 5 we have to get the reminder zero.

this c program logic is very simple. firstly we declares the variables count sum etc as integers. Now we accept the value for the range from the user.

Then we start a for loop from starting range value to end range value, inside the for loop we take each number and do a mod operation on that number, if the reminder is zero increment count plus 1 and add sum equal to sum + that number. also print that number as integer divisible by five.

===================================================================
#include <stdio.h>
 
#include <conio.h>
 
void main()
 
{
 
  int i, N1, N2, count = 0, sum = 0;   /* declares count, sum and two variables as integer */
 
  clrscr();
 
  printf ("Enter the value of N1 and N2\n");   /* user gives the value for lower and upper range */
 
  scanf ("%d %d", &N1, &N2);
 
  /*Count the number and compute their sum*/
 
  printf ("Integers divisible by 5 are\n");  
 
  for (i = N1; i < N2; i++) 
 
  {
 
     if (i%5 == 0)
 
     { 
 
	printf("%3d,", i);              /* using mod operator check the number is divisible by 5 */
 
	count++;
 
	sum = sum + i;                   /* add the numbers divisible by 5 to sum variable */
 
     }
 
  }
 
  printf ("\nNumber of integers divisible by 5 between %d and %d = %d\n",
 
	   N1,N2,count);
 
  printf ("Sum of all integers that are divisible by 5 = %d\n", sum);        /* displays the output of program */
 
 
}   /* End of main()*/
==================================================================
OUTPUT of C program to find the number of integers divisible by 5
==================================================================
Enter the value of N1 and N2
2
27
Integers divisible by 5 are
5, 10, 15, 20, 25,
Number of integers divisible by 5 between 2 and 27 = 5
Sum of all integers that are divisible by 5 = 75