c program the function accepts two integers you are required to calculate the sum of numbers divisible by 3 and 5 between given two numbers and return the same.
ip:12,50 op:90
Answers
Answer:
Program to print all the numbers divisible by 3 and 5 for a given number
Given the integer N, the task is to print all the numbers less than N, which are divisible by 3 and 5.Approach : For example, let’s take N = 20 as a limit, then the program should print all numbers less than 20 which are divisible by both 3 and 5. For this divide each number from 0 to N by both 3 and 5 and check their remainder. If remainder is 0 in both cases then simply print that number
Below is the implementaion
/ C++ program to print all the numbers
// divisible by 3 and 5 for a given number
#include <iostream>
using namespace std;
// Result function with N
void result(int N)
{
// iterate from 0 to N
for (int num = 0; num < N; num++)
{
// Short-circuit operator is used
if (num % 3 == 0 && num % 5 == 0)
cout << num << " ";
}
}
// Driver code
int main()
{
// input goes here
int N = 100;
// Calling function
result(N);
return 0;
}
// This code is contributed by Manish Shaw
// (manishshaw1)