How to Write a Program That Exponentiates using C

preview_player
Показать описание
In this video I will show you how to write a program that exponentiats in C. More precisely, given the base x and the exponent n, this program will return the value of x^n. I hope this video helps someone.

If you enjoyed this video please consider liking, sharing, and subscribing.

There are several ways that you can help support my channel:)

************Udemy Courses(Please Use These Links If You Sign Up!)*************
Abstract Algebra Course

Advanced Calculus Course

Calculus 1 Course

Calculus 2 Course

Calculus 3 Course

Calculus Integration Insanity

Differential Equations Course

College Algebra Course

How to Write Proofs with Sets Course

How to Write Proofs with Functions Course

Statistics with StatCrunch Course

Math Graduate Programs, Applying, Advice, Motivation

Daily Devotionals for Motivation with The Math Sorcerer

Thank you:)
Рекомендации по теме
Комментарии
Автор

I love that you use C! A true sorcerer

Bagunka
Автор

Just a few nitpickey things, but you should forward declare the power function before main and include the variable types in the parameters of power.

JJCUBER
Автор

Nice job ....just came handy when I didn't understand what I was doing and being mixed up ...This was very helpful... hope you make more nice and pleasant videos...keep it up !

smalljpmorgan
Автор

This is Amazing!, I'm just now taking a C course in my university and this came in the perfect moment, are you planning to do pointers and strings? I'm struggling a bit with those, I would love to see you explaining them a bit in the future! :D

dux
Автор

You can also use recursion, which greatly simplifies things (by applying the definition of exponentiation: x⁰ = 1, xⁿ⁺¹ = x · xⁿ):

double power(double base, unsigned exponent) {
if(exponent == 0) {
return 1;
}
return base * power(base, exponent - 1);
}

GRBtutorials
Автор

Hey Soccer
I ask how can we calculate x^n when n is rational or even irrational? I think we can use the definition of e^x as a sum, but idk how.

cono
Автор

Hey, do you do zoom tutoring for basic algebra? I have to take an ASVAB test for military. I really like your no non sense, straight forward teaching style. Please reach out if so.

skiz_
Автор

Really amazing please make more video like this please

mesh
Автор

Well this was unexpected and a pleasant surprise. Nice 👍🏼

Wandering_Horse
Автор

Hello Sir I have a question for you In trying to learn math like solving rational equations
But I seem to forget what I’ve learned I studied how to solve them but after 4-5 days I don’t remember it could you give me some tips how to not forget any math problem

evelinmartinschool
Автор

You should do some python programming videos!

stankdog
Автор

sir your code takes o(n) to run consider the below code it takes o(logn) to run

#include <bits/stdc++.h>
using namespace std;

long long power(long long a, long long b) {
long long result = 1;
while(b) {
if (b & 1)
result = result * a;
a = a * a;
b >>= 1;
}
return result;
}

int main() {
int x, y;
cin>>x>>y;
cout<<power(x, y)<<"\n";
return 0;
}

sainithinreddy
Автор

This video is unwatchable on a phone. Please zoom in on the text.

Algator
Автор

Too much code, and slow.

double pow(double x, int n)
{
if (n == 0) return 1;
return (n > 0) ? x * pow(x, n - 1) : 1 / x * pow(x, n + 1);
}

There are also faster ways to do this with the FPU. In Computer Science, we normally agree 0^0 = 1. It allows things to work. I wouldn't use this though. This is a more practical way of looking at the exponents. Welcome to programming in C.

ByronGoodman
Автор

oh come on, you're a mathematician. use haskell!

닐리아담