473,385 Members | 1,676 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,385 software developers and data experts.

how to write code for X power N with out using POW function.

Dear members can u please tell me how to write code for x power n with out using pow() function.The manipulation code must be in only one line.
Dec 18 '06 #1
2 10232
Dear members can u please tell me how to write code for x power n with out using pow() function.The manipulation code must be in only one line.

Hi buddy,

It very easy use pow() function.

Include a header file math.h and then add this function

z = pow( x, n );

That's it! it ll work fine..
Dec 18 '06 #2
Manjiri
40
Dear members can u please tell me how to write code for x power n with out using pow() function.The manipulation code must be in only one line.

Hello it's very easy... Just think on it and try.. If then too u did'nt get then look on this following solution...

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. int pw(int,int);
  3. int main()
  4. {
  5. int x,n,ans;
  6. printf("Enter the numbers:base and power\n");
  7. scanf("%d%d",&x,&n);
  8. ans=pw(x,n);
  9. printf("The ans is:  %d\n",ans);
  10. return 0;
  11. }
  12.  
  13.  
  14. int pw(int x,int n)
  15. {
  16. int i,y=1;
  17. if(n==0)
  18. return 0;
  19. else if(n==1)
  20. return x;
  21. else if(n==2)
  22. return(x*x);
  23. else
  24. {
  25. y=x*x;
  26. for(i=3; i<=n; i++)
  27. {
  28. y=y*x;
  29. }
  30. return (y);
  31. }
  32. }
Dec 18 '06 #3

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

Similar topics

2
by: Brett Baisley | last post by:
Hello I have a block of html code that I want to run by calling a javascript function to print it. Its basically a table with menu items in it that is the same for many pages, and instead of...
0
by: SRLoka | last post by:
I have a TCP server to which a number of mobile devices connect. If a device disconnects(mostly no clean close as they usually lose cell coverage or shutdown), and the server then tries to send...
67
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. ...
37
by: Protoman | last post by:
Hi!!! Protoman here, I need to write an infinite precision number class b/c I want to compute pi. Give me some sample code. Also, when I run my program and it computes pi, will my computer freeze...
9
by: Profetas | last post by:
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;
18
by: jacob navia | last post by:
In C, we have read-only memory (const), read/write memory (normal data), and write only memory. Let's look at the third one in more detail. Write only memory is a piece of RAM that can only...
21
by: utab | last post by:
Hi there, Is there a way to convert a double value to a string. I know that there is fcvt() but I think this function is not a part of the standard library. I want sth from the standard if...
10
by: Magnus | last post by:
I'm migrating an applicationf from Delphi5 to C# .net Framework 2.0, but have some problems convertingt the Power function, because it is not implemented in the framework Math library. Does anyone...
11
by: Steven D'Aprano | last post by:
I find myself writing command line tools in Python where I wish to include "verbose" output to stdout. I start with a helper function: def print_(obj, level=0): if _verbosity >= level:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.