Sei sulla pagina 1di 5

SAN Technology Training on Apr 7,8,9,10 @ Bangalore

Read More

C Program to Find the Number of Integers Divisible by 5


This C Program calculates the number of integers divisible by 5. This program checks if the given number is
divisible by 5 and then prints an appropriate message.

Here is source code of the C program to calculate the number of integers divisible by 5. The C program is
successfully compiled and run on a Linux system. The program output is also shown below.
1. /*
2. * C program to find the number of integers divisible by
3.
4.
5.
6.
7.

* 5 between the given range num1 and num2, where num1 < num2.
*
* Also find the sum of all these integer numbers which are divisible
* by 5 and display the total.
*/

8. #include <stdio.h>
9.
10. void main()
11. {
12. int i, num1, num2, count = 0, sum = 0;
13.
14. printf("Enter the value of num1 and num2 \n");
15. scanf("%d %d", &num1, &num2);
16. /* Count the number and compute their sum*/
17. printf("Integers divisible by 5 are \n");
18. for (i = num1; i < num2; i++)
19. {
20.
if (i % 5 == 0)
21.
{
22.
printf("%3d,", i);
23.
count++;
24.
sum = sum + i;
25.
}
26. }
27. printf("\n Number of integers divisible by 5 between %d and %d =
28. %d\n", num1, num2, count);
29. printf("Sum of all integers that are divisible by 5 = %d\n", sum);
30. }

advertisements

$ cc pgm18.c
$ a.out
Enter the value of num1 and num2
12 17
Integers divisible by 5 are
15,
Number of integers divisible by 5 between 12 and 17 = 1
Sum of all integers that are divisible by 5 = 15

Sanfoundry Global Education & Learning Series 1000 C Programs.


Heres the list of Best Reference Books in C Programming, Data-Structures and Algorithms
If you wish to look at other example programs on Simple C Programs, go to Simple C Programs. If you wish to
look at programming examples on all topics, go to C Programming Examples.

advertisements

Sponsored Links by Taboola

You May Like

11 Tips for Lowering Blood Sugar Levels


Remedist

7 Tricks For How To Learn Any Language In 1 Week


Babbel

Fly Around The World The Easy Way


Fortune Skyteam - Germany2

Gamers around the world have been waiting for this game!
Forge Of Empires - Free Online Game

Manish Bhojasia, a technology veteran with 19+ years @ Cisco & Wipro, is Founder and CTO at
Sanfoundry. He is Linux Kernel Developer and SAN Architect and is passionate about competency
developments in these areas. He lives in Bangalore and delivers focused training sessions to IT
professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage &
Cluster Administration, Advanced C Programming, SAN Storage Technologies, SCSI Internals and Storage
Protocols such as iSCSI & Fiber Channel. Stay connected with us below:
Google+ | Facebook | Twitter | LinkedIn

Subscribe Sanfoundry Newsletter and Posts


Name*

Email*

advertisements

Terms of Use & Privacy Policy | Copyright | Technology Groups | Interns | Jobs | Sitemap

2011-2016 Sanfoundry. All Rights Reserved.

Potrebbero piacerti anche