Question:
Write a Program using Functions that calculates X^Y where both X and Y are doubles and X is positive. (Hints: Call the function pow() in <math.h>)
18 12545
So what have you tried? Where are you stuck?
Question:
Write a Program using Functions that calculates X^Y where both X and Y are doubles and X is positive. (Hints: Call the function pow() in <math.h>)
I don't consider that a hint; I consider that a complete spoiler. If you don't recognize
a hint like that you wouldn't recognize a hint even if it were dancing on a piano
wearing a purple tutu singing "I am a hint; I am a hint".
kind regards,
Jos
i jus started to do programming since last month and i still a newbie =(
i cant solve the question ,it's hard for me =(
The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.
Please read the Posting Guidelines and particularly the Coursework Posting Guidelines.
Then when you are ready post a new question in this thread.
is it ok? -
#include <stdio.h>
-
int square(int y);
-
-
int main (void)
-
{
-
int x;
-
for (x = 0;x>=0;x++) {
-
printf ("%d",square (x) );
-
}
-
-
printf("\n");
-
-
return 0;
-
}
-
-
int square (int y)
-
{
-
return y*y;
-
}
Question:
Write a Program using Functions that calculates X^Y where both X and Y are doubles and X is positive. (Hints: Call the function pow() in <math.h>)
(define x x)
(define y y)
(pow x y)
hehehehe.
tis is wat i hav done ,but it seems not correct =( -
#include <stdio.h>
-
int square(int y);
-
-
int main (void)
-
{
-
int x;
-
for (x = 1;x>=0;x++) {
-
printf ("%d",square (x) );
-
}
-
-
printf("\n");
-
-
return 0;
-
}
-
-
int square (int y)
-
{
-
return y*y;
-
}
Why aren't you using the easy method your teacher suggested? Why are you reinventing something that has already been created?
Also, why use a for loop? Was that a requirement as well? FYI - you declare them as ints, not doubles.
tis is wat i hav done ,but it seems not correct =( -
for (x = 1;x>=0;x++) {
-
printf ("%d",square (x) );
-
}
-
}
X is equal than 1, continue while X is greater than 0, after each iteration, increase X by 1.
I hope you see atleast 1 problem with this for loop.
is it ok? -
#include <stdio.h>
-
int square(int y);
-
-
int main (void)
-
{
-
int x;
-
for (x = 0;x>=0;x++) {
-
printf ("%d",square (x) );
-
}
-
-
printf("\n");
-
-
return 0;
-
}
-
-
int square (int y)
-
{
-
return y*y;
-
}
i still have no idea about doubles =(
i still have no idea about doubles =(
http://www.cplusplus.com/doc/tutorial/variables.html
If you are having trouble with something that basic, we are going to have a difficult time helping you with your programs.
Ask to sit down and spend an hour with your teacher or TA going over variables, program structure, and control structures (loops), or you are going to have a LOT of trouble very quickly.
-
#include <stdio.h>
-
#include <math.h>
-
-
int main ()
-
{
-
double x = 1;
-
double y = 1;
-
double result;
-
-
for ( x = 1; x <= 10; x++ ){
-
printf("%f\n",result = pow(x,y) );
-
}
-
-
-
return 0;
-
}
-
i did it but the output is seems not correct:
1
2
3
4
5
6
7
8
9
10
#include <stdio.h>
#include <math.h>
int main ()
{
double x = 1;
double y = 1;
double result;
for ( x = 1; x <= 10; x++ ){
printf("%f\n",result = pow(x,y) );
}
return 0;
}
i did it but the output is seems not correct:
1
2
3
4
5
6
7
8
9
10
That output is perfectly correct because for every x != 0, x^1 == x.
kind regards,
Jos
-
#include <stdio.h>
-
#include <math.h>
-
-
int main ()
-
{
-
double x = 1;
-
double y = 1;
-
double result;
-
-
for ( x = 1; x <= 10; x++ ){
-
printf("%f\n",result = pow(x,y) );
-
}
-
-
-
return 0;
-
}
-
i did it but the output is seems not correct:
1
2
3
4
5
6
7
8
9
10
Okay, let's trace through one of these
x=1
y=1
for x =1
while x<10 // while 1< 10
print pow(x,y) // print x^y -> print 1^1(1)
x++ // x=2
while x< 10 // while 2 < 10
print pow (x,y) // print x^y -> print 2^1 (2)
etc...
What you are printing out is correct math. Set y to something else and you will see it.
it should not be correct..
becoz the output should be:
1
4
9
16
25
36
49
64
81
100
?
it should not be correct..
becoz the output should be:
1
4
9
16
25
36
49
64
81
100
?
No, not the way you have it written. You do nothing to 'y' through the whole thing. So it is always 1. You need to increment y.
im really stuck,i dunno how to fix it
#include <stdio.h>
#include <math.h>
int main (void)
{
double x;
double y;
double result;
printf("Enter an integer for x\n");
scanf("%d",&x);
printf("Enter an integer for y\n");
scanf("%d",&y);
result = pow(x,y);
printf("x raised to power y is %f\n",result);
return 0;
}
it not works,i input 8 as x and 2 as y,the output is 1...
First, please use CODE tags unless your code is something like one function call or some obviously readable block. Be on the safe side as a beginner and always use them.
Next, why declare x and y as doubles if you treat them as integers in your program? Shouldn't you rather treat them as doubles? For example, your scanf format specifier would be %f, not %d, right? (You should be verifying this with a C reference that you can easily google. Or type in "man scanf" in Google).
Sign in to post your reply or Sign up for a free account.
Similar topics
by: GM |
last post by:
Hello. I am starting my 7th week of an intro to programming class and have
a problem I have been working on. My instructor said we could look for
source code on the internet and use it as long as...
|
by: Ron Adam |
last post by:
Hi, I'm having fun learning Python and want to say thanks to everyone
here for a great programming language.
Below is my first Python program (not my first program) and I'd
apreciate any...
|
by: cj |
last post by:
Thanks to everyone that has helped me. Now I'm trying to write my first
program. I have an example of one that I need to write about. Any help
getting me started is appreciated. I'm having trouble...
|
by: zaidalin79 |
last post by:
I have a java class that goes for another week or so, and I am going to fail if I can't figure out this simple program. I can't get anything to compile to at least get a few points... Here are the...
|
by: coolindienc |
last post by:
I converted this program from using global variables to local variables. When I did that my while loop stopped working in my main function(module). Anyone, any idea why? I underlined the area where...
|
by: jbailey006 |
last post by:
I am trying to add the following information to a payroll program I am working on for assignment. Modify the Payroll Program so that it uses a class to store and retrieve the employee's name, the...
|
by: nexcompac |
last post by:
Ok, I posted a similar post but now need to jump back into it. Here is what I have been able to clean up. I am using textpad and jbuilder.
Still getting used to the whole java world and I am...
|
by: rohitsripathi |
last post by:
i need help writing this program... i am in college and i do not have time do this right now as i need to study for another test....but this is due tonight...i will pay $5 if you accept to do it and...
|
by: Starbuck01 |
last post by:
I have to write a program for my AP Computer Science Class. Here is the instructions.
The Police Department is asking for help in catching those who speed. You will write a batch style program...
|
by: strangetorpedo |
last post by:
The problem lies under where if (choice == '2') is...I need the program to keep prompting for num and den values as long as the user enters values less than or equal to 0. Once they are values...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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,...
|
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: 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...
| |