- 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

# Print values of ‘a’ in equation (a+b) <= n and a+b is divisible by x

Given with equation program must find the value of ‘a’ where a+b<=n and also divisible by x.

## Algorithm

START Step 1 -> Declare start variables b=10, x=9, n=40 and flag=0, divisible Step 2 -> Loop For divisible = (b / x + 1 ) * x and divisible <= n and divisible += x IF divisible - b >= 1 Print divisible-1 Set flag=1 End END STOP

## Example

#include <stdio.h> int main(int argc, char const *argv[]) { int b=10, x=9, n=40, flag = 0; int divisible; for (divisible = (b / x + 1 ) * x ; divisible <= n; divisible += x) { if ( divisible - b >= 1) { printf("%d ", divisible - b ); flag = 1; } } return 0; }

## Output

if we run above program then it will generate following output

8 17 26

- Related Questions & Answers
- Count number of pairs (A <= N, B <= N) such that gcd (A , B) is B in C++
- Count number of triplets (a, b, c) such that a^2 + b^2 = c^2 and 1<=a<=b<=c<= n in C++
- Find (a^b)%m where ‘a’ is very large in C++
- K-th digit in ‘a’ raised to power ‘b’ in C++
- Count pairs (a, b) whose sum of squares is N (a^2 + b^2 = N) in C++
- Count pairs (a, b) whose sum of cubes is N (a^3 + b^3 = N) in C++
- Add N digits to A such that it is divisible by B after each addition?
- Python a += b is not always a = a + b
- PHP program to find the sum of first n natural numbers that are divisible by a number ‘x’ or a number ‘y’
- Count of pairs from 1 to a and 1 to b whose sum is divisible by N in C++
- Minimum positive integer value possible of X for given A and B in X = P*A + Q*B in C++
- Check if N is divisible by a number which is composed of the digits from the set {A, B} in Python
- Count of all possible values of X such that A % X = B in C++
- Larger of a^b or b^a in C++
- Maximum positive integer divisible by C and is in the range [A, B] in C++

Advertisements