Hi I am using this function to power numbers
int power (int m, int n);
int power (int base, int n) {
int i,
p;
p = 1;
for (i = 1; i <= n; ++i)
p *= base;
return p;
}
but my problem is that I need to power using 1.05 or 2.33
and this isn't working.
Should I use float?
another question.
is there any function call to clear the screen?
(I was using the system(clear); but it is not compatible
with other systems.
is there any way to read the user return?
like
printf("press return to go back to menu");
wait_return=get char();
???
Thanks Profetas 9 1743
"Profetas" <xu*****@yahoo. com> wrote in message
news:56******** *************** *******@localho st.talkaboutpro gramming.com... Hi I am using this function to power numbers int power (int m, int n);
int power (int base, int n) { int i, p; p = 1; for (i = 1; i <= n; ++i) p *= base; return p; }
but my problem is that I need to power using 1.05 or 2.33 and this isn't working.
Should I use float?
#include <math.h> and use pow() which takes two doubles and returns a
double. another question. is there any function call to clear the screen? (I was using the system(clear); but it is not compatible with other systems.
not portably, you could either have a lot of '\n's or check which system you
are on with #ifdef. On most modern OSs system("clear") ; or system("cls")
would work, but you would have to check which one you require as mentioned. is there any way to read the user return? like
printf("press return to go back to menu"); wait_return=get char(); ???
I dont undersstand what you mean.
Allan
in comp.lang.c i read: Hi I am using this function to power numbers int power (int m, int n);
but my problem is that I need to power using 1.05 or 2.33 and this isn't working.
Should I use float?
well, 1.05 and 2.33 are floating point values of type double so using
double or float would make sense. is there a particular reason you
aren't using the pow function?
is there any function call to clear the screen?
standard c doesn't have any. you need something for your platform, which
would be off-topic in this group.
is there any way to read the user return? like
printf("pres s return to go back to menu"); wait_return=ge tchar();
this seems to read from the user (in most cases).
--
a signature
>> is there any way to read the user return? like
printf("press return to go back to menu"); wait_return=get char(); ???
I dont undersstand what you mean. Allan
I wanted some function that would wait
the user to press enter.
When I use getchar it expect a char and return won't
count as a char.
Profetas <xu*****@yahoo. com> wrote: is there any way to read the user return? like
printf("press return to go back to menu"); wait_return=get char(); ??? I dont undersstand what you mean. Allan
I wanted some function that would wait the user to press enter. When I use getchar it expect a char and return won't count as a char.
As the following little program will show you, the return key also
counts as a char:
#include <stdio.h>
#include <stdlib.h>
int main( void )
{
int key;
while ( 1 ) {
if ( ( key = getchar( ) ) == EOF )
return EXIT_SUCCESS;
printf( "Got a key: %d\n", key );
}
return EXIT_SUCCESS;
}
Even more, it will only returns after the user pressed <RETURN> (unless
you fiddled around too much with your terminal settings ;-) All you make
have to sure of is to read getchar() repeatedly until you find the '\n'
to empty the input buffer in case the user hit not only the <RETURN>
key. I.e. use something like
while ( ( key = getchar( ) ) != '\n' )
/* empty */ ;
Return, Jens
--
\ Jens Thoms Toerring ___ Je***********@p hysik.fu-berlin.de
\______________ ____________ http://www.toerring.de
Profetas wrote: is there any way to read the user return? like
printf("press return to go back to menu"); wait_return=get char(); ???
I dont undersstand what you mean.
I wanted some function that would wait the user to press enter. When I use getchar it expect a char and return won't count as a char.
Yes it will. Try calling:
#include <stdio.h>
void awaitreturn(voi d)
{
int ch;
while (('\n' != (ch = getchar())) && (EOF != ch)) continue;
}
--
fix (vb.): 1. to paper over, obscure, hide from public view; 2.
to work around, in a way that produces unintended consequences
that are worse than the original problem. Usage: "Windows ME
fixes many of the shortcomings of Windows 98 SE". - Hutchison
"Profetas" <xu*****@yahoo. com> wrote in message news:<56******* *************** ********@localh ost.talkaboutpr ogramming.com>. .. Hi I am using this function to power numbers int power (int m, int n);
int power (int base, int n) { int i, p; p = 1; for (i = 1; i <= n; ++i) p *= base; return p; }
but my problem is that I need to power using 1.05 or 2.33 and this isn't working.
Should I use float?
another question. is there any function call to clear the screen? (I was using the system(clear); but it is not compatible with other systems.
is there any way to read the user return? like
printf("press return to go back to menu"); wait_return=get char(); ???
Thanks Profetas
Hello
Use the standard c function
double pow(double x, double y)
it does exactly the things you what to do
Greetings Olaf
Profetas Wrote Hi I am using this function to power numbers int power (int m, int n);
int power (int base, int n) { int i, p; p = 1; for (i = 1; i <= n; ++i) p *= base; return p; }
but my problem is that I need to power using 1.05 or 2.33 and this isn't working.
Should I use float?
Allan Bruce Wrote
#include <math.h> and use pow() which takes two doubles >and returns a double.
I tried what you suggest and I got this error
/tmp/ccwFiFtL.o(.tex t+0x141): In function `mm':
: undefined reference to `pow'
collect2: ld returned 1 exit status
Thanks profetas
Profetas wrote: I tried what you suggest and I got this error
/tmp/ccwFiFtL.o(.tex t+0x141): In function `mm': : undefined reference to `pow' collect2: ld returned 1 exit status http://www.eskimo.com/~scs/C-faq/q14.3.html
"Profetas" <xu*****@yahoo. com> wrote in message news:<c2******* *************** ********@localh ost.talkaboutpr ogramming.com>. .. Profetas Wrote Hi I am using this function to power numbers int power (int m, int n);
int power (int base, int n) { int i, p; p = 1; for (i = 1; i <= n; ++i) p *= base; return p; }
but my problem is that I need to power using 1.05 or 2.33 and this isn't working.
Should I use float?
Allan Bruce Wrote
#include <math.h> and use pow() which takes two doubles >and returns a double.
I tried what you suggest and I got this error
/tmp/ccwFiFtL.o(.tex t+0x141): In function `mm': : undefined reference to `pow' collect2: ld returned 1 exit status
Thanks profetas
You need to get a math library linked with your executable. Consult
your compiler's documenation for how to do this. Following example is
for gcc.
dresnick(1224)$ cat foo.c
#include <stdio.h>
#include <math.h>
int main()
{
double result = pow (4.0,0.5);
printf("result is %f\n", result);
return 0;
}
dresnick(1225)$ gcc -Wall -ansi -pedantic -lm -o foo foo.c
dresnick(1226)$ foo
result is 2.000000 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stephane Belzile |
last post by:
Is there a way I can detect in vb.Net the power has switched to a UPS
unit in case of power failure?
Thanks
|
by: Roman Töngi |
last post by:
I just want to raise a number to a power.
e.g.:
16^2
The pow()-function of cmath seems to be not enough. I've read
about valarray. Is it really so difficult?
Can you give me an example.
Thanks Roman
|
by: Thiva Charanasri |
last post by:
http://www.poweroflanguage.org
Track: Computer Language
1st World Congress on the Power of Language:
Theory, Practice and Performance
Date: March 6 - 10, 2006
Bangkok, Thailand
On this very auspicious occasion, Thai people will join hands with
|
by: Thiva Charanasri |
last post by:
http://www.poweroflanguage.org
Track: Computer Language
1st World Congress on the Power of Language:
Theory, Practice and Performance
Date: March 6 - 10, 2006
Bangkok, Thailand
On this very auspicious occasion, Thai people will join hands with
|
by: Richard Fennell |
last post by:
Am trying to do ASP.NET development on my XP Prof. box logged in as a power
user (not the administrator I used to be).
As an admin user all is OK.
But as a power user, I have made sure my account to the power user,
debugging user and vs developers and all seems OK bar debugging ASP.NET.
I get an access denied error that I cannot connect the debugger. The help
informs that it is probably due the ASPNET work process not being the right
| |
by: mathon |
last post by:
hi,
i develeoped a recursive function for the power and it works fine
double power(double x, int n) {
if (n < 0)
return 1/power(x, -n);
else if (n == 0)
return 1.0;
|
by: mathon |
last post by:
hi,
i already posted an entry because of this problem, unfortunately i
havent solved it so far..:(
I have created a recursion for the calculation of the power like this:
double power(double x, int n) {
|
by: maxthebaz |
last post by:
Our machines have this requirement: if power failure occurs, many
important variables are to be resumed from where they were interrupted
after the machine is restarted (power on in this case). In other words,
the basic idea is to keep a snapshot of the state machine before it is
interrupted.
The board is provided with:
- a 32-bit H8S/2633 Hitachi microprocessor;
- a battery-backed memory (BBM), where these variables are stored; BBM
area...
|
by: greek |
last post by:
the question is to calculate x^n(x power n) (whr n can be +ve or -ve) by using recursion. the algorithm is
x= 1, n=0
1/x^n, n<0
x*x^(n-1), n>0
ive written the program it runs but im not having the correct values..here is the code:
#include<iostream.h>
#include<conio.h>
|
by: skanemupp |
last post by:
how do i solve power(5,1.3)?
def power(nbr, po):
if po==0:
return 1
if po>0:
return nbr*power(nbr, po-1)
if po<0:
return 1/power(nbr, -1*po)
|
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...
| |
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,...
|
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...
|
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...
|
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,...
|
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...
|
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();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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
| |