473,401 Members | 2,125 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,401 software developers and data experts.

What is the symbol used for power?

3
hi guys,
sorry... this might see a stupid question to you all as i am still a new to c++.
but i like to ask if i wanna to find the power. wat symbol do i use. as i know we use the following symbols for
addition +
substraction -
multiply *
division /
and so on. thus i like to ask wat symbol we actually use for power.
thnx and rgds,
sianz
Aug 20 '08 #1
6 8494
boxfish
469 Expert 256MB
Hi,
Unfortunately, there is no symbol to raise a number to a power. You have to #include <cmath> and use its pow() function. If you're squaring a value, it's probably best to just use the * operator and multiply the value by itself.
Hope this helps.
Aug 20 '08 #2
SiAnZ
3
ok
thanx alot.
now actully i done the program
but the program seems like got some bugs. like for example 17^23 mod 23 = 17 but i got -6. den 21^17 mod 61 = 29 but i got -59. den if i do 2^3 mod 5 =3 which i get the rite answer. the problem is like if i use big number to do, the output i got is wrong but if i use small number, i can get the correct input. can anyone help?



Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h> 
  2. #include <math.h>  
  3. using namespace std; 
  4. int main(void) 
  5. {     
  6. int integer1; //first number to be input     
  7. int integer2; //2nd number to be input     
  8. int integer3; //modular to be input     
  9. int integer4; //do the power function     
  10. int sum; //varible of thing to be stalled in          
  11.  
  12. printf( "pls enter number: \n" ); //promt for number     
  13. scanf("%d", &integer1);         
  14.  
  15. printf( "pls enter power: \n" ); //promt for power     
  16. scanf("%d", &integer2);          
  17.  
  18. printf( "pls enter modular: \n" ); //promt for modular     
  19. scanf("%d", &integer3);          
  20.  
  21. integer4 = pow(integer1,integer2);     
  22. //scanf("%d", &integer4);          
  23.  
  24. sum = integer4 % integer3;     
  25. printf("ans is %d\n", sum); //print sum          
  26. return 0;  } 
  27.  
Aug 20 '08 #3
Ganon11
3,652 Expert 2GB
How large is 17^23, or 23^17?

Hint: The largest number an int can carry is 2,147,483,647.
Aug 20 '08 #4
SiAnZ
3
actually i wan to calculate 17^ 23 mod 23 and 21^17 mod 61 etc... so if the largest int can carry, does it mean i have to use others insted of int?
Aug 20 '08 #5
Banfa
9,065 Expert Mod 8TB
No if you are using modulus division you can use the identity

(a * b) mod c = ((a mod c) * (b mod c)) mod c

If it is a power calculation

(a ^ b) mod c = ((a mod c) ^ b) mod c

At first this doesn't seem useful because in your examples c > a so a mod c == a but if instead of doing the ^ as a single function call you treat it as multiple multiplication (which you can since you are using integers so b is always an integer but we are constraining it to be always positive too) then you can do something like this.

(a ^ b) mod c = ((a mod c) ^ b) mod c

if b == 3

(a ^ b) mod c = (a * a * a) mod c

but

(a * b) mod c = ((a mod c) * (b mod c)) mod c

and

a * b * c = (a * b) * c

so

(a ^ b) mod c = ((((a mod c) * (a mod c)) mod c) * (a mod c)) mod c

Basically you will have to do the power calculation yourself using a loop and at every interim result (iteration) you apply the modulus to keep the values in range of your integers.

This should work as long as c-1 < sqrt(MAX_INT)



Of course another option is to use 64 bit integers that mamny platforms support today.
Aug 21 '08 #6
Laharl
849 Expert 512MB
Also, use <cstdio> and <cmath> rather than <stdio.h> and <math.h>, respectively. The .h style for C standard libraries is deprecated as of 1998 or so. Not a huge deal, just a nit to pick.
Aug 21 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: John Graat | last post by:
Hi all, I've built the STLport-462 library on AIX-4.3.3 using gcc-3.3.2. No errors during compilation. However, during linking the following error occurs: ld: 0711-317 ERROR: Undefined symbol:...
4
by: ±èµ¿±Õ | last post by:
Tell me why the symbol "_" use in the Library? For example, char *_itoa( int value, char *string, int radix ); But We use function "itoa(value,string,radix) "only. I want to know the...
23
by: JDeats | last post by:
Just spent some time browsing around here: http://msdn.microsoft.com/Longhorn/ I can see the benefits from WinFS (as long as we tag all in-coming data this should be nice, tagging everything...
2
by: AS | last post by:
Hi, I'm trying to use some power management features with windows 2000 Professional and I have visual studio .net 2003 installed with the latest service packs and everything... I want to write...
0
by: fake ID | last post by:
Since you can't search for these symbols used in asp.net "<%#" or '<%=' I thought i'd post this to make things a little easier to find. Potential search word combinations: -lessthan Percentage...
23
by: Xah Lee | last post by:
The Concepts and Confusions of Pre-fix, In-fix, Post-fix and Fully Functional Notations Xah Lee, 2006-03-15 Let me summarize: The LISP notation, is a functional notation, and is not a...
9
by: Prasad | last post by:
HI, I am a beginner in VC++.. I am trying to write a Win32 console application in visual studio.. I am using following header files.. #include <STRING> using namespace std; #include...
5
by: bonnielym84 | last post by:
Im new here..didnt noe whether is this the rite way to post my problem..Really need help here..i've been stucked in this error from last wk..My problem is like this..Im using VC++ 6.0 to compile my C...
6
by: ink | last post by:
Hi I am developing on a Symbol MC70 devices and in the past they have always realised an SDK for development including Symbol.Camera Wrapper. However it seems that for the MC35 they are not, or...
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: 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...
0
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...
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
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
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...
0
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...
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.