

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ program to find largest or equal number of A whose sum of digits is divisible by 4
Suppose we have a number A. We have to find nearest larger or equal interesting number for A. A number is said to be interesting number if its sum of digits is divisible by 4.
So, if the input is like A = 432, then the output will be 435, because 4 + 3 + 5 = 12 which is divisible by 4.
Steps
To solve this, we will follow these steps −
while (A / 1000 + A mod 1000 / 100 + A mod 100 / 10 + A mod 10) mod 4 is not equal to 0, do: (increase A by 1) return A
Example
Let us see the following implementation to get better understanding −
#include <bits/stdc++.h> using namespace std; int solve(int A) { while ((A / 1000 + A % 1000 / 100 + A % 100 / 10 + A % 10) % 4 != 0) { A++; } return A; } int main() { int A = 432; cout << solve(A) << endl; }
Input
432
Output
435
- Related Questions & Answers
- Program to find number of consecutive subsequences whose sum is divisible by k in Python
- C Program to check if a number is divisible by sum of its digits
- Find a Number X whose sum with its digits is equal to N in C++
- Count pairs in array whose sum is divisible by 4 in C++
- Largest number smaller than or equal to N divisible by K in C++
- Find M-th number whose repeated sum of digits of a number is N in C++
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M in C++
- Find the Largest number with given number of digits and sum of digits in C++
- C Program to check if a number is divisible by any of its digits
- Find number of substrings of length k whose sum of ASCII value of characters is divisible by k in C++
- Find numbers whose sum of digits equals a value
- Check whether sum of digits at odd places of a number is divisible by K in Python
- Program to find number of pairs from N natural numbers whose sum values are divisible by k in Python
- Find the minimum positive integer such that it is divisible by A and sum of its digits is equal to B in Python
- n-th number whose sum of digits is ten in C++
Advertisements