473,834 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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*pow er;
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("\nresul t 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
24 1746

"Three Headed Monkey" <fo************ ****@yahoo.comw rote 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*********@gm ail.comwrote:
>On Mar 12, 12:57 pm, Three Headed Monkey
<four_headed_m on...@yahoo.com 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)
{
int i,power;
power=n;
for(i=0;i<n;i=i +1)
power=power*pow er;
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("\nresul t 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,r es);
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@localhost writes:
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_Keit h) <ks***@mib.or g>
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.comw rote:
>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.comw rote:
>>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

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

Similar topics

0
1806
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 script: Description Given a table 'mailer' that has a column: emailaddr varchar(255) Create a new table to hold a count of email addresses by their domain name limited to those domains that have at least 100 addresses in the list and add a...
4
2002
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. ___________________________________________________________________________________________________________________ class Money {
2
2283
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 class for awhile and don't know what I'm doing. I have included my (probably wrong) answers for the first few questions. It would be great if someone could tell me what is missing or what I need to work on at least just for the first few. I...
6
1747
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++ and would like to also understand what im' doing.....to further my career.. i'll include the program after the description So my teacher gave the class an algorithm we have to manipulate......its a struct and i understand what is going on in...
3
2016
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 in a reference parameter variable, and validate it. This function should be called by main once for each of the 5 judges. My question is do i ask the judges to cin the score using cin. Or do I ? I dont know can someone please explian how to go...
1
1565
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 corresponding value of type double. If the string supplied is not a valid number, it should return 0.0 as its result. Note that you can use the method Double.parseDouble() to do the hard work for you. ...
8
29173
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 classes: Card.java, Deck.java and DeckTester.java. The specification for each class is given below. Card.Java This is a simple class that represents a playing card. Card has two attributes: • rank which is a String that represents the value...
0
9797
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9644
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10509
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10219
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9331
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7757
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6954
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5793
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3977
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.