- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures

- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces

# 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 Articles
- C Program to check if a number is divisible by sum of its digits
- Program to find number of consecutive subsequences whose sum is divisible by k in Python
- Find the largest 4 digit number divisible by 16.
- Find a Number X whose sum with its digits is equal to N in C++
- Largest number smaller than or equal to N divisible by K 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
- Sum of a two-digit number and the number obtained by reversing the digits is always divisible by?
- Find M-th number whose repeated sum of digits of a number is N in C++
- Program to find number of pairs from N natural numbers whose sum values are divisible by k in Python
- A number consists of two digits whose sum is five. When the digits are reversed, the number becomes greater by nine. Find the number.
- Find the minimum positive integer such that it is divisible by A and sum of its digits is equal to B in Python
- Check whether sum of digits at odd places of a number is divisible by K in Python
- PHP program to find the sum of first n natural numbers that are divisible by a number ‘x’ or a number ‘y’

Advertisements