473,385 Members | 1,944 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,385 software developers and data experts.

difficult to code

I have tried writing a program which should

1)get a number from user
2)calculate the following
for e.g if the input is 3 then 3
3
3
and the answer should be 19683.
3)similarly when the user entered 4 or 5 or any number it should
give the rquired result.
4)pow() SHOULD NOT TO BE USED

Nov 15 '05 #1
8 1656
shan wrote:
I have tried writing a program which should

1)get a number from user
2)calculate the following
for e.g if the input is 3 then 3
3
3
and the answer should be 19683.
Wrong. The result of the operation you wrote is not 19863. The correct
result is 7,625,597,484,987. Read again your math books from Primary
School. Either you don't want to perform the operation you wrote or you
didn't operate correctly.
3)similarly when the user entered 4 or 5 or any number it should
give the rquired result.
4)pow() SHOULD NOT TO BE USED


Ask somewhere else, this has nothing to do with C. And besides that,
it's not that difficult to code.

Nov 15 '05 #2
shan wrote:
I have tried writing a program which should

1)get a number from user
2)calculate the following
for e.g if the input is 3 then 3
3
3
and the answer should be 19683.
Strictly, that's the answer to (3 to the 3) to the 3, rather than 3 to the
(3 to the 3).
3)similarly when the user entered 4 or 5 or any number it should
give the rquired result.
4)pow() SHOULD NOT TO BE USED


I suggest you try a little harder. The problem specification appears to me
to be:

Let N be user input
Let F be N to the power N
Let S be F to the power N
Display S

Coding this in C is trivial, but beware! Even for very small N, the C
Standard does not guarantee that the result, S, can be calculated
accurately. If you need integer-perfect accuracy, I suggest unsigned long
(or, if you have a C99 compiler which you don't, unsigned long long) - but
be aware that you still won't get very far in terms of a valid input
domain.

Doubles give you a bit more scope, but lack integer-perfect accuracy after a
certain point.

If you need integer-perfect accuracy AND biggish inputs, then you might
consider using a bignum library such as GMP or Miracl.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
mail: rjh at above domain
Nov 15 '05 #3
shan wrote:
2)calculate the following
for e.g if the input is 3 then 3
3
3
and the answer should be 19683.


(3^3)^3 = 3^9 = 19683
3^(3^3) = 3^27 = 7625597484987 (43 bits)

P.S. "e.g." stands for "exempli gratia" which (roughly) translates to
"just because I'm a nice guy, here's an example fer ya." In other words,
there is no "for" before "e.g.".
Nov 15 '05 #4
In article <11**********************@o13g2000cwo.googlegroups .com>,
shan <sr**********@gmail.com> wrote:

I have tried writing a program which should

1)get a number from user
2)calculate the following
for e.g if the input is 3 then 3
3
3
and the answer should be 19683.
3)similarly when the user entered 4 or 5 or any number it should
give the rquired result.
4)pow() SHOULD NOT TO BE USED


Just out curiosity, is the fact that there are three 3's
significant? I mean, if the input was 4, should it
be four 4's:

4
4
4
4 = 340282366920938463463374607431768211456

or just

4
4
4 = 4294967296

that might make the problem even more difficult/interesting.

(Note I have chosen left associativity for consistency with
original message's result of 19683. My personal understanding
of associativity differs.)
--
7842++
Nov 15 '05 #5
On 2005-07-27 04:31:34 -0500, "shan" <sr**********@gmail.com> said:
I have tried writing a program which should

1)get a number from user
2)calculate the following
for e.g if the input is 3 then 3
3
3
and the answer should be 19683.
3)similarly when the user entered 4 or 5 or any number it should
give the rquired result.
4)pow() SHOULD NOT TO BE USED

Superpower, aka hyperpower and power tower, is a simple thing. You say:

3
3
3 = something too small.

That is a really huge number. If you want to deal with this, use
logarithms and exponentials (no pow() you say) and get the wrong
answer: it's a logarithmic approximation of the result, so big numbers,
less accuracy.

Now, all I can say to you, is: get a infinite precision algebra if you
really need.
Learn here: http://mathworld.wolfram.com/PowerTower.html

Use this: http://www.swox.com/gmp/
--
Sensei <se******@tin.it>

cd /pub
more beer

Nov 15 '05 #6
In article <nQVFe.21972$HV1.6690@fed1read07>,
an******@example.com (Anonymous 7843) wrote:
In article <11**********************@o13g2000cwo.googlegroups .com>,
shan <sr**********@gmail.com> wrote:

I have tried writing a program which should

1)get a number from user
2)calculate the following
for e.g if the input is 3 then 3
3
3
and the answer should be 19683.
3)similarly when the user entered 4 or 5 or any number it should
give the rquired result.
4)pow() SHOULD NOT TO BE USED


Just out curiosity, is the fact that there are three 3's
significant? I mean, if the input was 4, should it
be four 4's:

4
4
4
4 = 340282366920938463463374607431768211456

or just

4
4
4 = 4294967296

that might make the problem even more difficult/interesting.

(Note I have chosen left associativity for consistency with
original message's result of 19683. My personal understanding
of associativity differs.)


Hello.
The convention is a^b^c = a^(b^(c)) because (a^b)^c = a^(bc).
e.g

2
sqrt(pi) d -z
--------- -- erf(z) = e
2 dz

--
Michael Press
Nov 15 '05 #7
In article <ja************************@newsclstr02.news.prodi gy.com>,
Michael Press <ja**@abc.net> wrote:


In article <nQVFe.21972$HV1.6690@fed1read07>,
an******@example.com (Anonymous 7843) wrote:
In article <11**********************@o13g2000cwo.googlegroups .com>,
shan <sr**********@gmail.com> wrote:

I have tried writing a program which should

1)get a number from user
2)calculate the following
for e.g if the input is 3 then 3
3
3
and the answer should be 19683.
3)similarly when the user entered 4 or 5 or any number it should
give the rquired result.
4)pow() SHOULD NOT TO BE USED


Just out curiosity, is the fact that there are three 3's
significant? I mean, if the input was 4, should it
be four 4's:

4
4
4
4 = 340282366920938463463374607431768211456

or just

4
4
4 = 4294967296

that might make the problem even more difficult/interesting.

(Note I have chosen left associativity for consistency with
original message's result of 19683. My personal understanding
of associativity differs.)


Hello.
The convention is a^b^c = a^(b^(c)) because (a^b)^c = a^(bc).
e.g

2
sqrt(pi) d -z
--------- -- erf(z) = e
2 dz

--
Michael Press


That was from two months ago!
I look backward to hearing more about your time machine!
Nov 15 '05 #8
In article <BHA_e.16488$mH.11502@fed1read07>,
an******@example.com (Anonymous 7843) wrote:
In article <ja************************@newsclstr02.news.prodi gy.com>,
Michael Press <ja**@abc.net> wrote:


In article <nQVFe.21972$HV1.6690@fed1read07>,
an******@example.com (Anonymous 7843) wrote:
In article <11**********************@o13g2000cwo.googlegroups .com>,
shan <sr**********@gmail.com> wrote:
>
> I have tried writing a program which should
>
> 1)get a number from user
> 2)calculate the following
> for e.g if the input is 3 then 3
> 3
> 3
> and the answer should be 19683.
> 3)similarly when the user entered 4 or 5 or any number it should
> give the rquired result.
> 4)pow() SHOULD NOT TO BE USED

Just out curiosity, is the fact that there are three 3's
significant? I mean, if the input was 4, should it
be four 4's:

4
4
4
4 = 340282366920938463463374607431768211456

or just

4
4
4 = 4294967296

that might make the problem even more difficult/interesting.

(Note I have chosen left associativity for consistency with
original message's result of 19683. My personal understanding
of associativity differs.)


Hello.
The convention is a^b^c = a^(b^(c)) because (a^b)^c = a^(bc).
e.g

2
sqrt(pi) d -z
--------- -- erf(z) = e
2 dz

--
Michael Press


That was from two months ago!
I look backward to hearing more about your time machine!


Reading forward from the older posts on the server. Could
not pass up comment. You all write good expositions on C.
I enjoy the fine points of a discipline, and am always
ready for another paradigm to improve program structure.

--
Michael Press
Nov 15 '05 #9

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

Similar topics

54
by: Spammay Blockay | last post by:
I've been tasked with doing technical interviews at my company, and I have generally ask a range of OO, Java, and "good programming technique" concepts. However, one of my favorite exercises I...
12
by: Mike Dee | last post by:
A very very basic UTF-8 question that's driving me nuts: If I have this in the beginning of my Python script in Linux: #!/usr/bin/env python # -*- coding: UTF-8 -*- should I - or should I...
5
by: Nick Keighley | last post by:
Hi, In the beginning the code was:- BRUSHH new_brush = create_brush() BRUSHH old_brush = select_brush (new_brush) draw(...) select_brush (old_brush) destroy_brush (new_brush)
5
by: Bob | last post by:
Hi Everybody Difficult question Has anyone else used the "Using the Tab control as a container" database example that comes with the above book chapter 7 on the accompanying disc. It is a...
0
by: tom | last post by:
Hallo, I need help on MIDI file, and precisely about retrieving few note values (mainly the "Velocity" value, corrisponding to the intensity of a played note) while the MIDI is playing.
2
by: Eniac | last post by:
*argh* ... *pull hairs* I've recently started developing from ASP to ASP.NET The switch was fairly smooth since i had done some VB.net before ... then came...FORMS! :) I find it astounding...
12
by: RICHARD BROMBERG | last post by:
For the last couple of days I have been trying to learn how to solve this problem. I'm using Access 2000 I am posting it again and maybe I will be mofe successful. I have a text box and a...
14
AccessIdiot
by: AccessIdiot | last post by:
Hello all, A while ago I got a lot of help on building a bunch of forms tied to a somewhat complicated db. Now I'm back with a search form question. The guys that I built the db for - they...
2
TheServant
by: TheServant | last post by:
I have a difficult join situation which I am not quite sure on the SYNTAX or if it's even possible: $raw_alliance_info = mysql_query( "SELECT name, code, description, members, focus, bonus,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.