473,323 Members | 1,547 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

fuction to divide by three

Without using /,% and * operators. write a function to divide a
number by 3.
itoa() function is available

May 26 '07 #1
12 7045
ra******@gmail.com writes:
Without using /,% and * operators. write a function to divide a
number by 3.
Do your own homework.

--
Regards,
Hallvard
May 26 '07 #2
In article <11**********************@r19g2000prf.googlegroups .com>,
ra******@gmail.com wrote:
Without using /,% and * operators. write a function to divide a
number by 3.
itoa() function is available
Who needs itoa()? Assuming integer division and only positive inputs,
it's trivial, although not precisely efficient, or necessarily fast, to
simply do repetitive subtraction.

--
Don Bruder - da****@sonic.net - If your "From:" address isn't on my whitelist,
or the subject of the message doesn't contain the exact text "PopperAndShadow"
somewhere, any message sent to this address will go in the garbage without my
ever knowing it arrived. Sorry... <http://www.sonic.net/~dakiddfor more info
May 26 '07 #3
In article <hb**************@bombur.uio.no>,
Hallvard B Furuseth <h.**********@usit.uio.nowrote:
ra******@gmail.com writes:
Without using /,% and * operators. write a function to divide a
number by 3.

Do your own homework.
Hey! I just had a great idea... Let's see if this one gets him dinged:

int DivBy3(int x)
{
int q;

for (q=0;x>2;x-=3,q++);
return q;
}

(ROT-13)
Bs pbhefr, guvf yvggyr "dhvpx-a-qvegl" jvyy bayl jbex sbe cbfvgvir
vachgf, naq vg'f tbvat gb or (pbzcnengviryl fcrnxvat) fybjre guna gur
frpbaq pbzvat sbe ovt vachgf, ohg vg'yy qb gur wbo. Naq vg fubhyq or
"nqinaprq" rabhtu gung gur grnpure jvyy fync uvz sbe boivbhf purngvat vs
ur npghnyyl hfrf vg - n pynff ng gur yriry guvf bar frrzf gb or onfrq ba
uvf "qb zl ubzrjbex sbe zr" erdhrfgf jba'g unir gur svefg pyhr nobhg gur
"snapl" gevpx bs penzzvat vg nyy vagb n sbe () ybbc (vs gurl'ir rira
yrnearq nobhg gurz ng nyy lrg) naq jvgu uvf qvfcynlrq yriry bs
vtabenapr, V unir ab qbhog ur'yy or hanoyr gb rira ORTVA rkcynvavat ubj
vg jbexf jura gur grnpure nfxf uvz. Ubcrshyyl rafhevat ng yrnfg na S ba
guvf nffvtazrag sbe purngvat.

--
Don Bruder - da****@sonic.net - If your "From:" address isn't on my whitelist,
or the subject of the message doesn't contain the exact text "PopperAndShadow"
somewhere, any message sent to this address will go in the garbage without my
ever knowing it arrived. Sorry... <http://www.sonic.net/~dakiddfor more info
May 26 '07 #4
ra******@gmail.com wrote:
>
Without using /,% and * operators. write a function to divide a
number by 3.
itoa() function is available
d = 0;
while ((a -= 3) 0) d++;

(I think this is such as not to be assumed the poor students work)

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
<http://kadaitcha.cx/vista/dogsbreakfast/index.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

May 26 '07 #5
In article <46***************@yahoo.com>,
CBFalconer <cb********@yahoo.comwrote:
ra******@gmail.com wrote:

Without using /,% and * operators. write a function to divide a
number by 3.
itoa() function is available

d = 0;
while ((a -= 3) 0) d++;

(I think this is such as not to be assumed the poor students work)
Heh... GMTA :)

--
Don Bruder - da****@sonic.net - If your "From:" address isn't on my whitelist,
or the subject of the message doesn't contain the exact text "PopperAndShadow"
somewhere, any message sent to this address will go in the garbage without my
ever knowing it arrived. Sorry... <http://www.sonic.net/~dakiddfor more info
May 26 '07 #6
CBFalconer said:
ra******@gmail.com wrote:
>>
Without using /,% and * operators. write a function to divide a
number by 3.
itoa() function is available

d = 0;
while ((a -= 3) 0) d++;

(I think this is such as not to be assumed the poor students work)
Since the itoa function is available, wouldn't it be simpler to use:

result_of_division_by_3 = itoa(n);

Of course, this assumes that itoa divides its numeric input by 3, but
that's not an unreasonable assumption, given the question text.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
May 26 '07 #7
On 2007-05-26 07:30:18 -0700, ra******@gmail.com said:
Without using /,% and * operators. write a function to divide a
number by 3.
itoa() function is available
Here ya' go; enjoy:

#include <stdbool.h>
#include <stdio.h>
#include <complex.h>

int divide(int n, unsigned d)
{
int j,l;
for(j=0;j<d;j-=(int)cpow(I,2));
{
int k=0;
if(n>=0) for(k=n,l=0;k>=j;k-=j,++l);
else for(k=-n,l=0;k>=j;k-=j,--l);
}

return l;
}

int divide_by_3(int i)
{
return divide(i, 3);
}

int main()
{
int i;

while(true)
{
printf("Enter a number (enter a non-number to quit): ");
fflush(stdout);

if(scanf("%d", &i) != 1)
{
return 0;
}
else
{
printf("%d / 3 == %d\n", i, divide_by_3(i));
}
}
}

--
Clark S. Cox III
cl*******@gmail.com

May 26 '07 #8
On May 26, 3:30 pm, rajm2...@gmail.com wrote:
Without using /,% and * operators. write a function to divide a
number by 3.
itoa() function is available
double divide_by_3 (double x) {
return x 0.0 ? exp (log (x) - log (3.0)) :
x < 0.0 ? -exp (log (-x) - log (3.0)) : x;
}
May 28 '07 #9
ra******@gmail.com wrote On 05/26/07 10:30,:
Without using /,% and * operators. write a function to divide a
number by 3.
itoa() function is available
#include <stdlib.h>
int divideBy3(int aNumber) {
div_t d = div(aNumber, 3);
return d.quot;
}

--
Er*********@sun.com
May 29 '07 #10
ra******@gmail.com wrote:
>
Without using /,% and * operators. write a function to divide a
number by 3.
itoa() function is available
Untested:

int DivideByThree(int number)
{
char mybuf[64];
sprintf(mybuf,"exit `expr %d / 3`",number);
return( system(mybuf) );
}

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h|
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

May 29 '07 #11
On May 28, 3:15 pm, "christian.bau" <christian....@cbau.wanadoo.co.uk>
wrote:
On May 26, 3:30 pm, rajm2...@gmail.com wrote:
Without using /,% and * operators. write a function to divide a
number by 3.
itoa() function is available

double divide_by_3 (double x) {
return x 0.0 ? exp (log (x) - log (3.0)) :
x < 0.0 ? -exp (log (-x) - log (3.0)) : x;
}
I like this one. I do see a minor problem for x == 0.

May 29 '07 #12
On May 29, 11:21 am, user923005 <dcor...@connx.comwrote:
On May 28, 3:15 pm, "christian.bau" <christian....@cbau.wanadoo.co.uk>
wrote:
On May 26, 3:30 pm, rajm2...@gmail.com wrote:
Without using /,% and * operators. write a function to divide a
number by 3.
itoa() function is available
double divide_by_3 (double x) {
return x 0.0 ? exp (log (x) - log (3.0)) :
x < 0.0 ? -exp (log (-x) - log (3.0)) : x;
}

I like this one. I do see a minor problem for x == 0.
As the wise baboon in "The Lion King" or Ben Pfaff might say:
"Look Harder."

Indeed, the matter is cared for.

May 29 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Szaki | last post by:
I use a BulkLoad to import file.xml to my base MS Server 2000. To import this xml file I need schema file. Mayby you know how to do this file mechanicy f.g. mayby somebody have some script in .net...
4
by: Paolo | last post by:
I am having some problem with a Year Function. I have form on which I have 4 field which indicate dates and an additional form which sums those dates: These are the fields: YEARS...
4
by: Macin | last post by:
Hi, How to efficently divide big array into small arrays as showed below? IN xxxxxxxxxxxxxx xxxxx xxxxx xxxxx xxxxxxxxxxxxxx xxxxx xxxxx xxxxx...
3
by: mike | last post by:
i've already used static fuction to make website i wanna common module that's why i used static fuctions. may be it's more than 100 fuction ...is it ok?
3
by: Umesh | last post by:
What is the use by making function Static.
0
by: Hellogeetu | last post by:
hello friends I m using datareports, and filled the data in the report using coding now a problem arrises that i want to show the aggrigate of each field and also % of each field for which i have...
8
by: contactmayankjain | last post by:
Hi, Can you tell me is there some procedure to calculate the number of calls of a function during run time? How to insert a counter and how to increment it? and possibly which function have...
27
by: jty0734 | last post by:
i wanna large divide. input is 1~1024 bit integer. first, i think using sub is solution. so i made two array. and sub divisor to dividend. but this situation happen.
14
by: Default User | last post by:
Hi, If I have three 64 bit integers and I want to do this operation on them: x*y/z Lets say that what we are multiplying by (y) is offset by what we are dividing by (z) so that the final...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.