Thursday, July 9, 2020

Power Function In C

Power Function In C How To Best Utilize Power Function In C? Back Home Categories Online Courses Mock Interviews Webinars NEW Community Write for Us Categories Artificial Intelligence AI vs Machine Learning vs Deep LearningMachine Learning AlgorithmsArtificial Intelligence TutorialWhat is Deep LearningDeep Learning TutorialInstall TensorFlowDeep Learning with PythonBackpropagationTensorFlow TutorialConvolutional Neural Network TutorialVIEW ALL BI and Visualization What is TableauTableau TutorialTableau Interview QuestionsWhat is InformaticaInformatica Interview QuestionsPower BI TutorialPower BI Interview QuestionsOLTP vs OLAPQlikView TutorialAdvanced Excel Formulas TutorialVIEW ALL Big Data What is HadoopHadoop ArchitectureHadoop TutorialHadoop Interview QuestionsHadoop EcosystemData Science vs Big Data vs Data AnalyticsWhat is Big DataMapReduce TutorialPig TutorialSpark TutorialSpark Interview QuestionsBig Data TutorialHive TutorialVIEW ALL Blockchain Blockchain TutorialWhat is BlockchainHyperledger FabricWhat Is EthereumEthereum TutorialB lockchain ApplicationsSolidity TutorialBlockchain ProgrammingHow Blockchain WorksVIEW ALL Cloud Computing What is AWSAWS TutorialAWS CertificationAzure Interview QuestionsAzure TutorialWhat Is Cloud ComputingWhat Is SalesforceIoT TutorialSalesforce TutorialSalesforce Interview QuestionsVIEW ALL Cyber Security Cloud SecurityWhat is CryptographyNmap TutorialSQL Injection AttacksHow To Install Kali LinuxHow to become an Ethical Hacker?Footprinting in Ethical HackingNetwork Scanning for Ethical HackingARP SpoofingApplication SecurityVIEW ALL Data Science Python Pandas TutorialWhat is Machine LearningMachine Learning TutorialMachine Learning ProjectsMachine Learning Interview QuestionsWhat Is Data ScienceSAS TutorialR TutorialData Science ProjectsHow to become a data scientistData Science Interview QuestionsData Scientist SalaryVIEW ALL Data Warehousing and ETL What is Data WarehouseDimension Table in Data WarehousingData Warehousing Interview QuestionsData warehouse architectureTalend T utorialTalend ETL ToolTalend Interview QuestionsFact Table and its TypesInformatica TransformationsInformatica TutorialVIEW ALL Databases What is MySQLMySQL Data TypesSQL JoinsSQL Data TypesWhat is MongoDBMongoDB Interview QuestionsMySQL TutorialSQL Interview QuestionsSQL CommandsMySQL Interview QuestionsVIEW ALL DevOps What is DevOpsDevOps vs AgileDevOps ToolsDevOps TutorialHow To Become A DevOps EngineerDevOps Interview QuestionsWhat Is DockerDocker TutorialDocker Interview QuestionsWhat Is ChefWhat Is KubernetesKubernetes TutorialVIEW ALL Front End Web Development What is JavaScript â€" All You Need To Know About JavaScriptJavaScript TutorialJavaScript Interview QuestionsJavaScript FrameworksAngular TutorialAngular Interview QuestionsWhat is REST API?React TutorialReact vs AngularjQuery TutorialNode TutorialReact Interview QuestionsVIEW ALL Mobile Development Android TutorialAndroid Interview QuestionsAndroid ArchitectureAndroid SQLite DatabaseProgramming aria-current=page>Uncat egorizedHow To Best Utilize Power Func... AWS Global Infrastructure C Programming Tutorial: The Basics you Need to Master C Everything You Need To Know About Basic Structure of a C Program How to Compile C Program in Command Prompt? How to Implement Linear Search in C? How to write C Program to find the Roots of a Quadratic Equation? Everything You Need To Know About Sorting Algorithms In C Fibonacci Series In C : A Quick Start To C Programming How To Reverse Number In C? How To Implement Armstrong Number in C? How To Carry Out Swapping of Two Numbers in C? C Program To Find LCM Of Two Numbers Leap Year Program in C Switch Case In C: Everything You Need To Know Everything You Need To Know About Pointers In C How To Implement Selection Sort in C? How To Write A C Program For Deletion And Insertion? How To Implement Heap Sort In C? How To Implement Bubble Sort In C? Binary Search In C: Everything You Need To Know Binary Search Introduction to C P rogramming-Algorithms What is Objective-C: Why Should You Learn It? How To Implement Static Variable In C? How To Implement Queue in C? How To Implement Circular Queue in C? What is Embedded C programming and how is it different? How To Best Utilize Power Function In C? Published on Sep 10,2019 33.4K Views edureka Bookmark Finding power of a number is a very common operation in programming logic. In this article we will understand how to write a program by using Power Function In C to calculate power of a number. Following pointers will be covered in this article,Logic For Power MultiplicationWriting a Custom Power FunctionPower Function in CLet us start with understanding how to write a program to calculate power of a number.Logic For Power Multiplication23 = 2*2*2 = 8To find the 2^3, you need to multiply 2 thrice. This can be simply achieved using for loop.For above example, base = 2, exponent = 3.for (exponent=3; exponent0; exponent--) { result = result * base; }Lets look at the C program implementing the same.Example #include stdio.h int main() { int base, exponent; int result = 1; printf(Enter a base number: ); scanf(%d, base); printf(Enter an exponent: ); scanf(%d, exponent); for (exponent; exponent0; exponent--) { result = result * base; } printf(Answer = %lld, result); return 0; }Output:Moving On with this article on Power Function In CWriting a Custom Power FunctionYou can also create a function to calculate the power which you can call anytime you want to calculate the power of any integer.int power(int base, int exponent) { int result=1; for (exponent; exponent0; exponent--) { result = result * base; } return result; }Lets look at the complete code how to use this function.Example#include stdio.h int power(int base, int exponent){ int result=1; for(exponent; exponent0; exponent--){ result = result * base; } return result; } int main() { int base, exponent; printf(Enter a base number: ); scanf(%d, base); printf(Enter an exponent: ); scanf(%d, exponent); int res = power(base, exponent); printf(Answer = %lld, res); return 0; }Output:This technique only works if the exponent is a positive integer. If you want to find the power of a number where the exponent is a real number, you need to use pow() function.Moving On with this article on Power Function In CPower Function in CThe pow() function is used to find the power of a given number.It returns x raised to the power of y(i.e. xy).The pow() function is present in math.h header file. So, you need to import math.h header file in the program to use pow() function.#include math.hThe declaration of the power function is as follows:Declaration: double pow(double base, double exponent);The pow() function takes two arguments (i.e. base exponent) returns the result of raising base to the power exponent.Calling the power function:pow(2.4, 3.2)where 2.4 is the base 3.2 is the exponentLets quickly look at an example to understand how to use pow() function in a program.Example:#include stdio.h #include math.h int main() { double base, expo, res; printf(Enter a base number: ); scanf(%lf, base); printf(Enter an exponent: ); scanf(%lf, expo); res = pow(base, expo); printf(%.1lf^%.1lf = %.2lf, base, expo, res); return 0; }OutputNow, after executing the above programs you would have understood how to use power function in C. I hope this article was informative and added value to you.Stay tuned for more tutorials on similar topics.You may also checkout our training program to get in-depth knowledge on jQuery along with its various applications, you canenroll herefor live online training with 24/7 support and lifetime access.Implement the above code with different strings and modifications. Now, we have a good understanding of all key concepts related to the pointer.Got a question for us? Mention them in the comments section of this blog and we will get back to you.Recommended blogs for you How To Become A DevOps Engineer? | DevOps Engineer Road Map Read Article Why Edureka’s Pedagogy results in a steep learning curve Read Article Load Testing using JMeter : How to Measure Performance in CMD Read Article Data Analyst Salary : How much Does a Data Analyst Earn? Read Article How to Install Appium: Step- by-Step Complete Tutorial Read Article How to Become a Certified Scrum Product Owner? Read Article What is Decision Table in Software Testing? Read Article Vol. XVIII â€" Edureka Career Watch â€" 10th Aug 2019 Read Article How to Implement Linear Search in C? Read Article What is the Difference between Agile and Scrum? Read Article What are the 7 Principles of Software Testing? Read Article Bugs in Software Testing â€" What, Where and How Read Article SAFe Agile Certification Exam Requirements: Everything You Need to Know Read Article International Students Day: Inspirational Edureka Learners Stories Read Article Top 10 Reasons to Learn Ethical Hacking Read Article #IndiaITRepublic â€" Top 10 Facts about IT Startups Read Article JMeter vs LoadRunner Battle of the Best Performance Testing Tool Read Article Infographic Top 10 Programming Languages to Learn in 2020 Read Article C Programming Tutorial: The Basics you Need to Master C Read Article Top 10 Technologies Disrupting the IT Landscape in 2020 You Need to Know Read Article Comments 0 Comments Trending Courses Python Certification Training for Data Scienc ...66k Enrolled LearnersWeekend/WeekdayLive Class Reviews 5 (26200)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.