The product of N and the largest odd number of digits in C
Given a number N with we have to product the number with its largest odd digit. If there is no odd digit then print -1.
Like we have initialized N with “153” and the largest odd digit in this number is 5 so the result would be the product of 153 with 5 i.e. 153 * 5 = 765 and if the number has no odd digit like 246 then the output must be -1.
Input − N = 198
Output − 1782
Explanation − 198 * 9 = 1782
Input − N = 15382
Output − 76910
Explanation − 15382 * 5 = 76910
Approach used below is as follows to solve the problem −
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Example
演示
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
输出
如果运行上述代码,将会生成以下输出−
1 |
|
The above is the detailed content of The product of N and the largest odd number of digits in C. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Windows 10 Professional Edition is a very easy-to-use computer system. There are both 64-bit and 32-bit versions, and the 32-bit version is better to use. What we will describe below is an introduction to the advantages of 32-bit version. How many bits is Windows 10 Professional Edition? Answer: Both 32-bit and 64-bit are available. Win10 Professional Edition is available in 32-bit and 64-bit versions. This article mainly introduces the advantages of 32-bit. Let’s take a look. 1. Excellent compatibility performance 1. First of all, we want to emphasize that Windows 10 Professional 32-bit performance is very superior in terms of compatibility. Its extremely high stability allows most existing 32-bit applications to run smoothly. 2. For you, this means enjoying the convenience brought by the latest operating system while

When a computer processes data, the number of bits of binary data that can be directly processed at one time is called the word length. The word length refers to the number of bits of binary data that the computer can directly process at one time. The longer the word length, the stronger the overall performance of the computer.

The series of squares of the first n odd numbers takes the square of the first n odd numbers in the series. The series is: 1,9,25,49,81,121…The series can also be written as -12,32,52,72,92,112….The sum of this series has a mathematical formula -n(2n+1)(2n -1)/3=n(4n2-1)/3For example, Input:N=4Output:sum=Explanation 12+32+52+72=1+9+25+49=84 Using the formula, sum=4 (4(4)2-1)/3=4(64-1)/3=4(63)/3=4*21=84 Both methods are good, but the method using mathematical formulas is better , which reduces the time complexity since it does not use a look

Weneedtofindthenumberofdigitsinthenthnumbermadeofgivenfourdigits1,2,3,and4.Theserieswiththeabovefourdigitsisasfollows1,2,3,4,11,12,13,14,21,22,23,24...Weneedtofindthenumberofdigitsofthenthnumberfromtheaboveseries.Ifyoucarefullyobservethepattern,youwi

In this section, we will see how to check whether a number is odd or even without using any conditional statements like <, <=, !=, >, >=, ==. We can easily check if the number is odd or even by using conditional statement. We can divide the number by 2 and check if the remainder is 0. If 0, it is an even number. Otherwise, we can AND the number with 1. If the answer is 0, it is an even number, otherwise it is an odd number. Conditional statements cannot be used here. We'll see two different ways to check whether an odd or even number is present. Method 1 Here we will create an array of strings. The index 0 position will hold "even" and the index 1 position will hold "odd". We can divide numbers

The average of odd numbers up to a given odd number is a simple concept. You just need to find the odd numbers up to that number, then add them and divide by that number. If you want to find the average of odd numbers up to n. Then we will find the odd numbers from 1 to n and add them together and divide by the number of odd numbers. Example The average of odd numbers up to 9 is 5, i.e. 1+3+5+7+9=25=>25/5=5 There are two ways to calculate the average of odd numbers up to n, where n is an odd number using a loop using the formula Program to find the average of odd numbers up to n, using a loop. To find the average of odd numbers up to n, we will add all the numbers up to n and divide by the number of odd numbers up to n. Program to calculate average of odd natural numbers up to n - example code

The pairwise product of the set X={a,b,c} can be defined as the sum of the products of all possible set pairs. The pairs of sets are Y={a*a,a*b,a*c,b*b,b*c,c*c}, where the products are commutative. Therefore, the pairwise product of set X is the sum of the elements of set Y, which is aa+ab+ac+bb+bc+cc. In mathematical terms, the sum of possible pairwise products can be expressed as: $$\mathrm{\displaystyle\sum\limits_{i=1,j=i}^{i\leqn,j\leqn}\:(i, j)=i\timej}$$Problem StatementGiven a number n. In the range (1, n), including n and 1, find

GivenanumberNwithwehavetoproductthenumberwithitslargestodddigit.Ifthereisnoodddigitthenprint-1.LikewehaveinitializedNwith“153”andthelargestodddigitinthisnumberis5sotheresultwouldbetheproductof153with5i.e.153*5=765andifthenumberhas
