ivanakarpuzova

Благ број

Oct 16th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.    int n, m;
  7.    scanf("%d %d", &n, &m);
  8.  
  9.    int temporary,blagBroj;
  10.    int lastDigit;
  11.    int flag;
  12.    int najmalBlagBroj = 10000000;
  13.  
  14.    while(n <= m)
  15.    {
  16.        temporary = n;
  17.        while(temporary > 0)
  18.        {
  19.            lastDigit = temporary%10;
  20.            if(lastDigit%2 == 0 || lastDigit == 0)
  21.             {
  22.                 flag = 1;
  23.             }
  24.             else
  25.             {
  26.                 flag = 0;
  27.                 break;
  28.             }
  29.             temporary/=10;
  30.        }
  31.        if(flag == 1)
  32.        {
  33.             blagBroj = n;
  34.             if(najmalBlagBroj > blagBroj)
  35.             {
  36.                najmalBlagBroj = blagBroj;
  37.             }
  38.        }
  39.        n++;
  40.    }
  41.         printf("%d", najmalBlagBroj);
  42.     return 0;
  43. }
Add Comment
Please, Sign In to add comment