N与C中最大的奇数位数的乘积

N与C中最大的奇数位数的乘积

  • Take the input N.

  • Traverse every digit and look for odd digits

  • Find the largest odd element.

  • Product the largest off element with the original number N.

  • If there is no odd element update result with -1.

  • Return the result.

  • Algorithm

    Start In function int largestodd(int n) Step 1→ Declare and Initialize large as -1 Step 2→ Loop While n > 0 Set digit as n % 10 If digit % 2 == 1 && digit > large then, Set large as digit Set n as n / 10 Step 3→ Return large In function int findproduct(int n) Step 1→ Declare and Initialize large set largestodd(n) Step 2→ If large == -1 then, Return -1 Step 3→ Return (n * large) In function int main() Step 1→ Initialize n as 15637 Print the results from calling findproduct(n) Stop登录后复制