Print and Sum of all the Multiples of 3 or 5 up to 999



Print and Sum of all the Multiples of 3 or 5 up to 999.

Hints:

For example, to find the multiples of 3, multiply 3 by 1, 3 by 2, 3 by 3, and so on. To find the multiples of 5, multiply 5 by 1, 5 by 2, 5 by 3, and so on. The multiples are the products of these multiplications.

Some examples of multiples can be found below. In each example, the counting numbers 1 through 8 are used. However, the list of multiples for a whole number is endless.

Example 1:  
Find the multiples of the whole number 4.
Multiplication:  
4 x 1
4 x 2
4 x 3
4 x 4
4 x 5
4 x 6
4 x 7
4 x 8
Multiples of 4:  
4
8
12
16
20
24
28
32
Solution:  
The multiples of 4 are 4, 8, 12, 16, 20, 24, 28, 32,...




Example 2:  
Find the multiples of the whole number 5.
Multiplication:  
5 x 1
5 x 2
5 x 3
5 x 4
5 x 5
5 x 6
5 x 7
5 x 8
Multiples of 5:  
5
10
15
20
25
30
35
40
Solution:  
The multiples of 5 are 5, 10, 15, 20, 25, 30, 35, 40,...
 







Source Code:

#include<stdio.h>
int main()
{
    int sum = 0;
    int i;
    printf("The multiples are :");
    for (i=1; i < 1000; i++)
    {
        if (i % 5 == 0 || i % 3 == 0 )
        {
       
        printf(" %d",i);
        sum += i;
          }
    }

    printf(" \n\nThe sum is: %i\n\n", sum);

    return 0;
}
<< Go to Index Page >>

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন