473,803 Members | 2,807 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 #1
24 1744
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*pow er;
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("\nresul t 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_mo n...@yahoo.comw rote:
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
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);
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_mo n...@yahoo.comw rote:
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_mo n...@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_mo n...@yahoo.comw rote:
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.na mewrites:
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.comw rote:
>
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*pow er;
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("\nresul t 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

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

Similar topics

0
1805
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
2000
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
2282
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
1746
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
29172
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
10550
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10317
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...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
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...
1
7604
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
6844
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
5633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2972
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.