Advertisement
haunted_mind

l2e1uvp

Nov 4th, 2020
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.75 KB | None | 0 0
  1. program l2e1uvp;
  2. {Ivan Ryvonenko, PM-12}
  3. {change odd digits of the first num with the max digit of the second num}
  4. {without arrays}
  5. uses crt;
  6. var
  7.   max_d:integer;
  8.   first,second,result,step_ten:longint;
  9. begin
  10.   clrscr;
  11.  
  12.   write('Enter first and second num: ');
  13.   readln(first,second);
  14.  
  15.   max_d:=second mod 10;
  16.   while second>=1 do
  17.   begin
  18.     if (second mod 10)>max_d then
  19.       max_d:=second mod 10 ;
  20.     second:=second div 10;
  21.   end;
  22.  
  23.   result:=0;
  24.   step_ten:=1;
  25.   while first>=1 do
  26.   begin
  27.     if (first mod 10) mod 2 = 0 then
  28.       result:=result + max_d*step_ten
  29.     else
  30.       result:=result + (first mod 10)*step_ten;
  31.     step_ten:=step_ten*10;
  32.     first:=first div 10;
  33.   end;
  34.  
  35.   writeln('result is : ',result);
  36.  
  37.   readln;
  38. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement