Accessibility Links

Skip to main contentAccessibility help
Accessibility feedback
Celebrating PopcornCelebrating Popcorn
Celebrating Popcorn
Press / to jump to the search box
Sign in

Filters and Topics

All
Images
Videos
Shopping
Forums
News
Web
More
About 3,110 results (0.46 seconds) 

Search Results


Write a function to divide a number by 3 without using /, % ...

Stack Overflow
https://stackoverflow.com › questions › write-a-functio...
Stack Overflow
https://stackoverflow.com › questions › write-a-functio...
Write a function to divide a number by 3 without using /, % and * operators. itoa() available? Ask Question. Asked 14 years, 8 months ago.
18 answers  ·  Top answer: Are you supposed to use itoa() for this assignment? Because then you could use that to convert ...

Divide a number by 3 without using division, multiplication ...

Stack Overflow
https://stackoverflow.com › questions › divide-a-numbe...
Stack Overflow
https://stackoverflow.com › questions › divide-a-numbe...
Without using / , % and * operators, write a function to divide a number by 3. itoa() is available. The above was asked from me in an ...
3 answers  ·  Top answer: The below code takes in 2 integers, and divides the first by the second. It supports ...
Questions & answers
Stack Overflow
Question
Write a function to divide a number by 3 without using /, % and * operators. itoa() available?
Answer · 14 votes
Are you supposed to use itoa() for this assignment? Because then you could use that to convert to a base 3 string, drop the last character, and then restore back to base 10.
More
Stack Overflow
Question
Without using /, % and * operators, write a function to divide a number by 3. itoa() is available. The above was asked from me in an interview and I couldn't really come up with an answer. I thought of converting the number to a string and adding all the digits, but that will just tell me whether number is divisible or not. Or, by repeated subtraction it can also tell me the remainder. But, how do I obtain the quotient on division?
Answer · 1 vote
The below code takes in 2 integers, and divides the first by the second. It supports negative numbers. int divide (int a, int b) { if (b == 0) //throw division by zero error //isPos is used to check whether the answer is positive or negative int isPos = 1; //if the signs are different, the answer will be negative if ((a < 0 && b > 0) || (a > 0 && b < 0)) int isPos = 0; a = Math.abs(a); b = Math.abs(b); int ans = 0; while (a >= b) { a = a-b; ans++; } if (isPos) return 0-ans; return ans; }
More
DaniWeb
Question
Without using /,% and * operators. write a function to divide a number by 3, itoa() function is available.
Answer · 0 votes
If you think about it you can divide by just using subtraction and a for() loop. Since you have this function itoa() available I'm assuming you are only using integers, which means you do not have to worry about remainders/decimals. Not gonna give you any code because you clearly just rewrote the assignment requirements, so give it a shot and if you have any questions post code and outline where you are having issues.
More
Stack Overflow
Question
I was given this question in an interview to describe the output in comments. unsigned int d2(unsigned int a) { __int64 q = (__int64)a * 0x0AAAAAAAB; // (2^33+1) / 3 return (unsigned int)(q >> 33); } I have checked other questions in Stackoverflow related to division by 3 but none seems so fast and small. Can anybody help me in explaining how the function is giving the output written in comments ?
Answer · 10 votes
The function divides a 32-bit unsigned number by 3. If you multiply by 2^33 and then divide by 2^33 (by right shifting), then you get the original number. But if you multiply by (2^33)/3 and then divide by 2^33, you effectively divide by three. The last digit is B instead of A to cause the result to be rounded up. There is no need to actually write this in your code because the compiler will usually do this for you. Try it and see. (Furthermore, for a signed input, the compiler can safely generate a signed right shift, but the C language does not define such an operation.)
More
Apple Support Community
Question
How to divide in Numbers
Answer · 3 votes
in Nimbers, in formula, keyboard don't allowse me to type this sign - / Why?
More
Stack Overflow
Question
Divide by 3, function in C#
Answer · 3 votes
If this is what you need (numbers increase columnwise but rows need to be filled first): for 16: 0 6 11 1 7 12 2 8 13 3 9 14 4 10 15 5 for 17: 0 6 12 1 7 13 2 8 14 3 9 15 4 10 16 5 11 You need to define which column is getting the remainders: int remainder = total % 3; if remainder is 1, only first column is 6 elements. if remainder is 2, first & second columns are 6 elements. You need to calculate startIndex and endIndex according to this. So; int pageSize = total / 3; int remainder = total % 3; int startIndex = column * pageSize + min(column, remainder); int endIndex = startIndex + pageSize + (remainder > column ? 1 : 0); should work. I just tested it, it works for different rowsizes than 3. Here is how I got the formulas, drawing tables is good practice for sorting out such algortihms: r:Remainder, c:column, ps:pagesize (as calculated above) StartingIndex: . |r:0 |r:1 |r:2 ---------------------- c:0|0 |0 |0 ---------------------- c:1|ps |ps+1 |ps+1 ----------------------…
More
Stack Overflow
Question
Recursive function to know if a number is divisible by 3
Answer · 8 votes
• The most straightforward solution is to use modulo 3 to check for divisibility, but that's not going to be recursive. • An alternate solution is to recursively keep dividing by 3 until you get down to 1, but that will stack overflow for large values. • A third solution, which lends itself to recursion, is to leverage the property that if the sum of the digits of a number is divisible by 3, then the number is divisible by 3. Here's an implementation of the third option that avoids modulo arithmetic and copes with very large numbers: def divThree(num): if num < 10: return (num in [3, 6, 9]) else: return divThree(sum([int(digit) for digit in str(num)])) You can add 0 to the list in the first return if you want to consider it divisible by 3 as well. If you want to accommodate both positive and negative values, prepend: if num < 0: return divThree(-num) as the first check to be performed.
More
Stack Overflow
Question
Return value in Javascript function (Sum of number divided by 3)
Answer · 2 votes
You should have a variable to sum numbers which satisfies condition numberArray[i] % 3 == 0: function sumNumbersBy3(numberArray) { let sum = 0 for(let i = 0; i < numberArray.length; i++) { if (numberArray[i] % 3 == 0) sum += numberArray[i]; } return sum; } In addition, you can use reduce method: const result = arr.reduce((a, c, i) => { (c % 3 == 0) ? a += c : 0; return a; }, 0); An example: function sumNumbersBy3(numberArray) { let sum = 0 for(let i = 0; i < numberArray.length; i++) { if (numberArray[i] % 3 == 0) sum += numberArray[i]; } return sum; } console.log("sumNumbersBy3: ", sumNumbersBy3([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])); let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; const result = arr.reduce((a, c, i) => { (c % 3 == 0) ? a += c : 0; return a; }, 0); console .log(`Using reduce method: ${result}`); Run code snippetHide resultsExpand snippet
More
Stack Overflow
Question
Recursive function divide a number
Answer · 2 votes
I think you need something like this int divide(int a, int b){ if(a - b <= 0){ return 1; } else { return divide(a - b, b) + 1; } }
More
Stack Overflow
Question
For example if you take the following example into consideration. 100.00 - Original Number 33.33 - 1st divided by 3 33.33 - 2nd divided by 3 33.33 - 3rd divided by 3 99.99 - Is the sum of the 3 division outcomes But i want it to match the original 100.00 One way that i saw it could be done was by taking the original number minus the first two divisions and the result would be my third number. Now if i take those 3 numbers i get my original number. 100.00 - Original Number 33.33 - 1st divided by 3 33.33 - 2nd divided by 3 33.34 - 3rd number 100.00 - Which gives me my original number correctly. (33.33+33.33+33.34 = 100.00) Is there a formula for this either in Oracle PL/SQL or a function or something that could be implemented? Thanks in advance!
Answer · 7 votes
This version takes precision as a parameter as well: with q as (select 100 as val, 3 as parts, 2 as prec from dual) select rownum as no ,case when rownum = parts then val - round(val / parts, prec) * (parts - 1) else round(val / parts, prec) end v from q connect by level <= parts no v === ===== 1 33.33 2 33.33 3 33.34 For example, if you want to split the value among the number of days in the current month, you can do this: with q as (select 100 as val ,extract(day from last_day(sysdate)) as parts ,2 as prec from dual) select rownum as no ,case when rownum = parts then val - round(val / parts, prec) * (parts - 1) else round(val / parts, prec) end v from q connect by level <= parts; 1 3.33 2 3.33 3 3.33 4 3.33 ... 27 3.33 28 3.33 29 3.33 30 3.43 To apportion the value amongst each month, weighted by the number of days in each month, you could do this instead (change the level <= 3 to change the number of months it is calculated for): with q as ( select add_months(date '2013-07-01…
More
Feedback
People also ask
How do you write a divide function?
How to divide a number by 3?
How do I divide a number by 3 in Excel?
How do you divide a number by 3 equal parts?
Feedback

how to use itoa() function to divide a number by 3 - c++

DaniWeb
https://www.daniweb.com › programming › threads › h...
DaniWeb
https://www.daniweb.com › programming › threads › h...
May 1, 2012 — Without using /,% and * operators. write a function to divide a number by 3, itoa() function is available.
3 answers  ·  Top answer: If you think about it you can divide by just using subtraction and a for() loop. Since you have ...

Without using /, % and * operators. Write a function to divide a ...

JobBuzz
https://jobbuzz.timesjobs.com › interview › question › al...
JobBuzz
https://jobbuzz.timesjobs.com › interview › question › al...
TriZetto India interview question: Without using /, % and * operators. Write a function to divide a number by 3. itoa() function is available. posted for ...

README.md - yfcheng/hackerrank

GitHub
https://github.com › yfcheng › hackerrank › blob › master
GitHub
https://github.com › yfcheng › hackerrank › blob › master
Write a function to divide a number by 3 without using +, -, *, / or % operators. Write a function to determine if a number is a power of two. Write a ...

why can i not divide this? - Javascript - Bytes

bytes.com
https://bytes.com › topic › 89570-why-can-i-not-divide
bytes.com
https://bytes.com › topic › 89570-why-can-i-not-divide
Jul 20, 2005 — ... operators. write a function to divide a number by 3. itoa() function is available. C / C++ · 8. 4807 · Divide by Zero Question. by: =?Utf-8?B ...

Adobe India Written Test 2006

GeekInterview.com
https://www.geekinterview.com › question_details
GeekInterview.com
https://www.geekinterview.com › question_details
write a function to divide a number by 3. itoa() function is available. 5) Wap to swap two integer pointers. 6)Write a funcn int round(float x) to round off ...

GitHub - yfcheng/hackerrank: Solutions for some of the ...

GitHub
https://github.com › yfcheng › hackerrank
GitHub
https://github.com › yfcheng › hackerrank
Write a function to divide a number by 3 without using +, -, *, / or % operators. Write a function to determine if a number is a power of two. Write a ...

Adobe Placement Paper Pattern (Written Test)

IndiaBIX
https://www.indiabix.com › placement-papers › adobe
IndiaBIX
https://www.indiabix.com › placement-papers › adobe
write a function to divide a number by 3. itoa() function is available. 5) Wap to swap two integer pointers. 6)Write a funcn int round(float x) to round off ...

Placement Assistance

GeekInterview.com
http://www.geekinterview.com › General › Placements
GeekInterview.com
http://www.geekinterview.com › General › Placements
Jan 9, 2024 — write a function to divide a number by 3. itoa() function is available. 5) Wap to swap two integer pointers. 6)Write a funcn int round(float x) ...
People also ask
Feedback
People also search for
Write a function to divide a number by 3 without
Write a function to divide a number by 3 using
Divide by 3 using bitwise operators
FPGA divide by 3
Divide by 3 using shift
Binary division by 3
How to divide using shift operator
Fast integer division by constant

Page Navigation

1234Next

Footer Links

Google apps