473,399 Members | 3,919 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,399 software developers and data experts.

not a homework question


write a program in "C" language that computes 9^(8^(7^(6^(5^(4^(3^(2^1)))))))

I tried

#include <stdio.h>

int pow(int n)
{
int i,power;
power=n;
for(i=0;i<n;i=i+1)
power=power*power;
return power;
}

void main()
{
int result;
char ignore;
result= pow(9,pow(8,pow(7,pow(6,pow(5,pow(4,pow(3,pow(2,1) )))))));
printf("\nresult is %d", result);
printf("\nPress ENTER");
gets(&ignore);
}
but it does not work.

how to do that in "C" standard language?

I am using lcc-win32 compiler & windows 98.

help!

Mar 12 '08 #1
24 1708
On Wed, 12 Mar 2008 05:57:12 +0100,Three Headed Monkey wrote:
write a program in "C" language that computes
9^(8^(7^(6^(5^(4^(3^(2^1)))))))

I tried

#include <stdio.h>

int pow(int n)
Change the name please. C has a std library function with the same
name and it's prototype is:

double pow(double x, double y);
{
int i,power;
power=n;
for(i=0;i<n;i=i+1)
power=power*power;
return power;
}

void main()
main() is never void in C.

{
int result;
char ignore;
result=
pow(9,pow(8,pow(7,pow(6,pow(5,pow(4,pow(3,pow(2,1) )))))));

Your _own_ pow only takes one parameter, why here it has two??
printf("\nresult is %d", result);
I suspect it overflows, since 'result' is only an int.
printf("\nPress ENTER");
gets(&ignore);
gets() is considered harmful, NEVER use it.
}
but it does not work.

how to do that in "C" standard language?
I am afraid you can't, the result may be too big. You can choose
a non-standard libary that supports huge number operations,
e.g. gmp.

Mar 12 '08 #2
Three Headed Monkey wrote:
write a program in "C" language that computes 9^(8^(7^(6^(5^(4^(3^(2^1)))))))
I don't think you can in standard C, the result will be huge...

--
Ian Collins.
Mar 12 '08 #3
On Mar 12, 12:57 pm, Three Headed Monkey
<four_headed_mon...@yahoo.comwrote:
write a program in "C" language that computes 9^(8^(7^(6^(5^(4^(3^(2^1)))))))

I tried

#include <stdio.h>

int pow(int n)
{
int i,power;
power=n;
for(i=0;i<n;i=i+1)
power=power*power;
return power;

}

void main()
{
int result;
char ignore;
result= pow(9,pow(8,pow(7,pow(6,pow(5,pow(4,pow(3,pow(2,1) )))))));
printf("\nresult is %d", result);
printf("\nPress ENTER");
gets(&ignore);

}

but it does not work.

how to do that in "C" standard language?

I am using lcc-win32 compiler & windows 98.

help!
First, you may want to have the pow function take 2 arguments: int
pow(int a, int n) { ... }
Second, the pow function defined in math.h does the job for you,
except that it deals with doubles: float pow(double a, double n)
returns a to the power of n as a float. So if you want to deal with
integers you have to convert the result.
Finally you may want to use a loop to do this. It'd look like this:

#include <math.h>
#include <stdio.h>
int main(){
double res=1;
int n;
for( n=2; n<=9; n++ )
res = pow((double)n,res);
printf("res=%f\n",res);
return 0;
}

Don't forget to link with the math library when compiling (-lm)

However this might overflow, resulting in res reaching inf. You can
try using long double and powl... Or more complicated stuff. Any idea
of what the resulting number might be?
Mar 12 '08 #4
Three Headed Monkey <four_headed_mon...@yahoo.comwrote:
Subject: not a homework question
Your subject should reflect the nature of your problem,
not merely that you have one.

It's not homework questions we mind, rather it's homework
questions that are quoted verbatim without so much as an
attempt.
write a program in "C" language that computes
9^(8^(7^(6^(5^(4^(3^(2^1)))))))
#include <stdio.h>

int main(void)
{
printf("%d\n", 9^(8^(7^(6^(5^(4^(3^(2^1))))))) );
return 0;
}

If you mean exponentiation, then realise it's pretty big!
Just 5^(4^(3^(2^1))) alone yields a 183000+ digit number.
Raise 6 to the power of that and you have... big!
I am using lcc-win32 compiler & windows 98.
Ah well... the non-standard extension qfloat should knock
that over easily. ;)

--
Peter
Mar 12 '08 #5
On Mar 11, 9:57*pm, Three Headed Monkey <four_headed_mon...@yahoo.com>
wrote:
write a program in "C" language that computes 9^(8^(7^(6^(5^(4^(3^(2^1)))))))
I guess that even LCC's qfloat data type will be too small.
Do you have any idea how many digits there are in that number?
Mar 12 '08 #6
Three Headed Monkey said:
>
write a program in "C" language that computes
9^(8^(7^(6^(5^(4^(3^(2^1)))))))
#include <stdio.h>

int main(void)
{
printf("%d\n",
9^(8^(7^(6^(5^(4^(3^(2^1))))))));
return 0;
}

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Mar 12 '08 #7
On Mar 11, 10:35*pm, Peter Nilsson <ai...@acay.com.auwrote:
Three Headed Monkey <four_headed_mon...@yahoo.comwrote:
Subject: not a homework question

Your subject should reflect the nature of your problem,
not merely that you have one.

It's not homework questions we mind, rather it's homework
questions that are quoted verbatim without so much as an
attempt.
write a program in "C" language that computes
9^(8^(7^(6^(5^(4^(3^(2^1)))))))

* #include <stdio.h>

* int main(void)
* {
* * printf("%d\n", 9^(8^(7^(6^(5^(4^(3^(2^1))))))) );
* * return 0;
* }

If you mean exponentiation, then realise it's pretty big!
Just 5^(4^(3^(2^1))) alone yields a 183000+ digit number.
Raise 6 to the power of that and you have... big!
I am using lcc-win32 compiler & windows 98.

Ah well... the non-standard extension qfloat should knock
that over easily. ;)
I doubt it.
Maple with precision set to 10,000,000 digits overflowed:
Digits=10000000; y := 9.^(8.^(7.^(6.^(5.^(4.^(3.^(2.^1.)))))));
10 = 10000000

Error, (in evalf/power) argument too large
>
Mar 12 '08 #8
Micah Cowan <mi***@cowan.namewrites:
Otherwise, you may be best-suited using the standard library's own
pow() function along with a floating point type (double would make
sense, given that's what pow() deals in). OTOH, if you happen to have
an implementation with <tgmath.h(and don't care to be portable to
them wot don't), you might opt for long double.
(Obviously, I wasn't thinking too clearly on the magnitude of this
number...)

--
Micah J. Cowan
Programmer, musician, typesetting enthusiast, gamer...
http://micah.cowan.name/
Mar 12 '08 #9
In article <12******************@aioe.org>, Three Headed Monkey <fo****************@yahoo.comwrote:
>
write a program in "C" language that computes 9^(8^(7^(6^(5^(4^(3^(2^1)))))))
Do you have even the slightest idea how large that number is? Did you perhaps
mean to type * instead of ^ ?
>
I tried

#include <stdio.h>

int pow(int n)
{
int i,power;
power=n;
for(i=0;i<n;i=i+1)
power=power*power;
return power;
}
Examine what you've written here a little more carefully, why don't you, and
see exactly what this function calculates. If you want to compute a^b, one
might suppose that you'd probably want a function that accepts both a and b as
input parameters.
>
void main()
{
int result;
char ignore;
result= pow(9,pow(8,pow(7,pow(6,pow(5,pow(4,pow(3,pow(2,1) )))))));
printf("\nresult is %d", result);
printf("\nPress ENTER");
gets(&ignore);
}
but it does not work.
A little more explanation would be helpful. Start with a complete description
of the manner in which it "does not work", including what you expect it to do
that it does not, and what it does that you expect it not to do.
Mar 12 '08 #10

"Three Headed Monkey" <fo****************@yahoo.comwrote in message
news:12******************@aioe.org...
>
write a program in "C" language that computes
9^(8^(7^(6^(5^(4^(3^(2^1)))))))
So if it's not homework, where does the problem come from? I suspect you
don't really to know the answer to this.

The algorithm can be done neatly in C using integer arithmetic. You were on
the right lines with your code, but you should have tested with a smaller N.

However, it is likely to overflow above N=4. Using bigger ints will help a
little but
will not come near N=9. This is my version tested to N=4:
#include <stdio.h>

int solve(int);

int main(void)
{int n,result;

n=4;

result=solve(n);

printf("Answer for N = %d is %d\n",n,result);

}

int solve(int n)
{
int i,x,a;

if (n<=1) return 1;

x=solve(n-1);

a=n;
for (i=1; i<x; ++i) a*=n;

return a;

}

--
Bart

Mar 12 '08 #11
On Tue, 11 Mar 2008 22:25:01 -0700 (PDT), Brice Rebsamen
<br*********@gmail.comwrote:
>On Mar 12, 12:57 pm, Three Headed Monkey
<four_headed_mon...@yahoo.comwrote:
>write a program in "C" language that computes 9^(8^(7^(6^(5^(4^(3^(2^1)))))))

I tried

#include <stdio.h>

int pow(int n)
{
int i,power;
power=n;
for(i=0;i<n;i=i+1)
power=power*power;
return power;

}

void main()
{
int result;
char ignore;
result= pow(9,pow(8,pow(7,pow(6,pow(5,pow(4,pow(3,pow(2,1) )))))));
printf("\nresult is %d", result);
printf("\nPress ENTER");
gets(&ignore);

}

but it does not work.

how to do that in "C" standard language?

I am using lcc-win32 compiler & windows 98.

help!

First, you may want to have the pow function take 2 arguments: int
pow(int a, int n) { ... }
Second, the pow function defined in math.h does the job for you,
except that it deals with doubles: float pow(double a, double n)
returns a to the power of n as a float. So if you want to deal with
Close. pow returns a double, not a float.
>integers you have to convert the result.
Finally you may want to use a loop to do this. It'd look like this:

#include <math.h>
#include <stdio.h>
int main(){
double res=1;
int n;
for( n=2; n<=9; n++ )
res = pow((double)n,res);
The cast is superfluous.
printf("res=%f\n",res);
%g might be better.
return 0;
}

Don't forget to link with the math library when compiling (-lm)
A system specific issue that may or may not be applicable to the OP.
>
However this might overflow, resulting in res reaching inf. You can
try using long double and powl... Or more complicated stuff. Any idea
of what the resulting number might be?

Remove del for email
Mar 12 '08 #12
Noob <root@localhostwrites:
Keith Thompson wrote:
[...]
>u7, u8, and u9 are Really Really Big (but still tiny compared to the
largest numbers that have actually been used in mathematics).

Are you referring to Graham's number?
World Champion largest number! ^_^

http://en.wikipedia.org/wiki/Graham%27s_number
Yup, that's the one I had in mind.

Graham's number is an upper bound on a number of dimensions for an
n-dimensional hypercube with certain characteristics. Graham and
Rothschild's paper provided a lower bound of 6; Martin Gardner called
this "perhaps the worst smallest-upper-bound ever discovered". (More
recently, the lower bound has been shown to be at least 11.)

So if you need to work with numbers that are too big to represent in
any arithmetic type in C, you can either come up with an alternate
representation (it wouldn't be hard to write C code that could
manipulate Knuth's up-arrow notation, used to describe Graham's
number), or improve your algorithm so you can use smaller numbers.
(There, it's topical!)

But consider this ...

(drum roll please)

GRAHAM'S NUMBER PLUS ONE!!!!

I win.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Mar 13 '08 #13
Three Headed Monkey wrote:
>
write a program in "C" language that computes
9^(8^(7^(6^(5^(4^(3^(2^1)))))))
Since 2 xor 1 is identically zero, that value suffices.

x = 0;

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
--
Posted via a free Usenet account from http://www.teranews.com

Mar 13 '08 #14
Op Wed, 12 Mar 2008 00:33:53 -0500 schreef CBFalconer:
Three Headed Monkey wrote:
>>
write a program in "C" language that computes
9^(8^(7^(6^(5^(4^(3^(2^1)))))))

Since 2 xor 1 is identically zero, that value suffices.
Since when? I get 3.
x = 0;
The value of the expression is 1.
--
Coos

Mar 13 '08 #15
On 13 Mar 2008 at 21:24, Coos Haak wrote:
Op Wed, 12 Mar 2008 00:33:53 -0500 schreef CBFalconer:
>Three Headed Monkey wrote:
>>>
write a program in "C" language that computes
9^(8^(7^(6^(5^(4^(3^(2^1)))))))

Since 2 xor 1 is identically zero, that value suffices.

Since when? I get 3.
> x = 0;
The value of the expression is 1.
CBF is a moaning old fart with no discernible technical knowledge or
skill. If you spend your time correcting his technical errors, you'll
waste a huge amount of time for no reward.

Mar 13 '08 #16
In article <17****************@aioe.org>, Three Headed Monkey <fo****************@yahoo.comwrote:
>It probably beyond my imagination,
Obviously.
>but when printing this number
on screen, how much time can I expect?
Considerably more than the age of the universe.
>If printed on paper, how many sheets will it needs?
There is not enough paper in existence to print this number. There has not
been enough paper manufactured since paper was invented to print this number.
There will not be enough paper manufactured between now and the end of time to
print this number. What part of "there are more digits in this number than
there are atoms in the universe" are you having trouble understanding?

--
Regards,
Doug Miller (alphageek at milmac dot com)

It's time to throw all their damned tea in the harbor again.
Mar 16 '08 #17
Doug Miller schreibt:
In article <17****************@aioe.org>, Three Headed Monkey
<fo****************@yahoo.comwrote:
>>It probably beyond my imagination,

Obviously.
>>but when printing this number
on screen, how much time can I expect?

Considerably more than the age of the universe.
>>If printed on paper, how many sheets will it needs?

There is not enough paper in existence to print this number. There has not
been enough paper manufactured since paper was invented to print this
number. There will not be enough paper manufactured between now and the
end of time to print this number. What part of "there are more digits in
this number than there are atoms in the universe" are you having trouble
understanding?
You should always save paper and print on both sides.

Mar 16 '08 #18
Richard Heathfield schrieb:
Three Headed Monkey said:

>>write a program in "C" language that computes
9^(8^(7^(6^(5^(4^(3^(2^1)))))))


#include <stdio.h>

int main(void)
{
printf("%d\n",
9^(8^(7^(6^(5^(4^(3^(2^1))))))));
return 0;
}
your system has a 255624-bit integer type?
Mar 17 '08 #19
Wolfgang Riedel said:
Richard Heathfield schrieb:
>Three Headed Monkey said:

>>>write a program in "C" language that computes
9^(8^(7^(6^(5^(4^(3^(2^1)))))))


#include <stdio.h>

int main(void)
{
printf("%d\n",
9^(8^(7^(6^(5^(4^(3^(2^1))))))));
return 0;
}
your system has a 255624-bit integer type?
Well, not unless I use my bignum library - but it isn't necessary for this
program. (Try it!)

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Mar 17 '08 #20
user923005 wrote:
Three Headed Monkey wrote:
Three Headed Monkey wrote:
>write a program in "C" language that computes
9^(8^(7^(6^(5^(4^(3^(2^1)))))))
<snip>
>It probably beyond my imagination, but when printing this number
on screen, how much time can I expect? If printed on paper, how many
sheets will it needs?

Grind up the entire universe and turn it into paper. It's not nearly
enough even to get started.
<snip>

What if you could employ compression on the sequence on the fly?

Mar 17 '08 #21
santosh wrote:
user923005 wrote:
>Three Headed Monkey wrote:
>>>Three Headed Monkey wrote:
write a program in "C" language that computes
9^(8^(7^(6^(5^(4^(3^(2^1)))))))

<snip>
>>It probably beyond my imagination, but when printing this number
on screen, how much time can I expect? If printed on paper, how many
sheets will it needs?
Grind up the entire universe and turn it into paper. It's not nearly
enough even to get started.

<snip>

What if you could employ compression on the sequence on the fly?
You can compress the output sequence as
9^(8^(7^(6^(5^(4^(3^(2^1)))))))
Mar 17 '08 #22
On Mar 17, 12:23*pm, santosh <santosh....@gmail.comwrote:
user923005 wrote:
Three Headed Monkey wrote:
Three Headed Monkey wrote:
write a program in "C" language that computes
9^(8^(7^(6^(5^(4^(3^(2^1)))))))

<snip>
It probably beyond my imagination, but when printing this number
on screen, how much time can I expect? If printed on paper, how many
sheets will it needs?
Grind up the entire universe and turn it into paper. *It's not nearly
enough even to get started.

<snip>

What if you could employ compression on the sequence on the fly?
Sjouke Burry took my snappy answer.

But as far as digits are concerned, I have seen an estimate that there
are about 10^87 elementary particles in the observable universe.
Supposing it is a factor of 1000 too low, then there would be 10^90
elementary particles. If we could encode a 10^10 digits on each
elementary particle and we had 10^90 of them, that would only be a
googol of digits (10^100) which is utterly dwarfed by this number
(which resembles in its construction Archimedian Cycles).
Mar 17 '08 #23
On Mar 17, 12:42*pm, Sjouke Burry <burrynulnulf...@ppllaanneett.nnlll>
wrote:
santosh wrote:
user923005 wrote:
Three Headed Monkey wrote:
Three Headed Monkey wrote:
write a program in "C" language that computes
9^(8^(7^(6^(5^(4^(3^(2^1)))))))
<snip>
>It probably beyond my imagination, but when printing this number
on screen, how much time can I expect? If printed on paper, how many
sheets will it needs?
Grind up the entire universe and turn it into paper. *It's not nearly
enough even to get started.
<snip>
What if you could employ compression on the sequence on the fly?

You can compress the output sequence as
9^(8^(7^(6^(5^(4^(3^(2^1)))))))
Which lead one man to exclaim:
"I couldn't see the forest for the threes!"
Mar 17 '08 #24
Richard Heathfield wrote:
Wolfgang Riedel said:
.... snip ...
>
>your system has a 255624-bit integer type?

Well, not unless I use my bignum library - but it isn't necessary
for this program. (Try it!)
[1] c:\c\junk>cat junk.c
#include <stdio.h>

int main(void) {
printf("%d\n", 9^(8^(7^(6^(5^(4^(3^(2^1))))))));
return 0;
}

[1] c:\c\junk>cc junk.c

[1] c:\c\junk>a
1

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.
--
Posted via a free Usenet account from http://www.teranews.com

Mar 18 '08 #25

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

Similar topics

0
by: | last post by:
I have this question for homework in an intro perl class, I was hoping for some quick help on this please...here is the question Using the Perl programming language, please prepare the following...
4
by: N3TB1N | last post by:
Here is my assignment. I am hoping that someone here quickly knows all of the correct answers... especially for question #5 and everything after. Thanks in advance. ...
2
by: N3TB1N | last post by:
Let me try again. I could use some help with this assignment, even though my teacher does not grade assignments.but because I need to know this stuff for a test very soon, but haven't been in...
6
by: wandafoda | last post by:
Sorry guys....another homework question and if you don't wanna help out..i understand. just to say..im' a chemical engineer and we are required at will to do whatever...thast why i have to take C++...
3
by: sewell | last post by:
Hey I have a problem with my homework. I really don't understand functions that well so bare with me. This the problem void getJudgeData ( ) should ask the user for a judge’s score, store it...
1
by: itgetsharder | last post by:
Hey, i was wondering if anyone could help me. i have two questions that i cannot complete for a homework assignment: This method should convert its parameter (a string like "3.1415") to the...
8
by: garyrowell | last post by:
I have been at this programme for hours trying to work out what is wrong. Any help would be very much appricated. Here is the breif I received. The program This week you are going to write three...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.