Write an algorithm and draw a flowchart to check if a number is divisible by 17 or not
Share
Write an algorithm and draw a flowchart to check if a number is divisible by 17 or not
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Answer:
// CPP Program to validate the above logic
#include <bits/stdc++.h>
using namespace std;
// Function to check if the
// number is divisible by 17 or not
bool isDivisible(long long int n)
{
while (n / 100)
{
// Extracting the last digit
int d = n % 10;
// Truncating the number
n /= 10;
// Subtracting the five times the
// last digit from the remaining number
n -= d * 5;
}
// Return n is divisible by 17
return (n % 17 == 0);
}
// Driver code
int main()
{
long long int n = 19877658;
if (isDivisible(n))
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}