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

Updated on: 30-Jul-2019

58 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements