C++ FOR BEGINNERS (2025) - For loop, How to calculate factorial of a number PROGRAMMING TUTORIAL

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 พ.ย. 2024

ความคิดเห็น • 71

  • @CodeBeauty
    @CodeBeauty  4 ปีที่แล้ว +20

    📚 Learn how to solve problems and build projects with these Free E-Books ⬇️
    C++ Lambdas e-book - free download here: bit.ly/freeCppE-Book
    Entire Object-Pascal step-by-step guide - free download here: bit.ly/FreeObjectPascalEbook
    🚀📈💻🔥 My Practical Programming Course: www.codebeautyacademy.com/
    Experience the power of practical learning, gain career-ready skills, and start building real applications!
    This is a step-by-step course designed to take you from beginner to expert in no time!
    💰 Here is a coupon to save 10% on your first payment (CODEBEAUTY_YT10).
    Use it quickly, because it will be available for a limited time.
    #include
    using namespace std;
    void main()
    {
    //The factorial of a number
    int number;
    cout > number;
    int factorial = 1;
    //6!=1*2*3*4*5*6=720
    //for (int i = 1; i = 1; i--) {
    factorial = factorial * i;
    }
    cout

  • @williamwelmans8648
    @williamwelmans8648 3 ปีที่แล้ว +5

    You are an excellent teacher! Thank you very much!

  • @angietodaro381
    @angietodaro381 4 ปีที่แล้ว +9

    Your explanation is so detailed, its great. Thanks so much :D

  • @venkateshnayak3454
    @venkateshnayak3454 3 ปีที่แล้ว

    The way you are teaching is very good..Thank you very much Saldina

  • @himanshugaikwad4998
    @himanshugaikwad4998 3 ปีที่แล้ว +4

    Ur teaching is so beautiful 🤩
    Just like YOU!!!!!

    • @CodeBeauty
      @CodeBeauty  3 ปีที่แล้ว +3

      Thank you so much! 😃

  • @lukachilukusha6437
    @lukachilukusha6437 3 ปีที่แล้ว +1

    Thanks a lot, I am learning from you different way to apply logic in programming. This is really helpful and I am how see different ways to solve different problems. Thanks 👍

  • @pbadibi
    @pbadibi ปีที่แล้ว +1

    thank you for existing 🦋

    • @CodeBeauty
      @CodeBeauty  ปีที่แล้ว

      Thank you for being such a supportive and kind person 💗

  • @Nishanth24s
    @Nishanth24s 3 ปีที่แล้ว

    This tutorial was very much helpful, even though i dont have any Coding background and i can easily understand your explanation and get the output seamless.
    Please do make a tutorial on
    1.Counting vowels.
    2. Reverse a string.
    3.To print Fibonacci series.
    Thank you Mam.

  • @jwawong
    @jwawong 4 ปีที่แล้ว +1

    Your videos are amazing! Thank you

  • @onetwo-di9cv
    @onetwo-di9cv 7 หลายเดือนก่อน

    Hi there, I am glad I find your brief tutorial for factorial using this for loop method. I tried & it's amazing!! But I find that the display result start to get wrong when it comes to number 13! & above. Is there any solution for this case?

  • @jaren_c
    @jaren_c 2 ปีที่แล้ว

    Excellent explanation!

  • @TheJoshuamcgowan
    @TheJoshuamcgowan 2 ปีที่แล้ว +1

    super helpful. thx!

  • @celestiaaldreaams
    @celestiaaldreaams 3 ปีที่แล้ว

    i did this in class today!! :)

  • @tankrides
    @tankrides ปีที่แล้ว

    double recursiveFactorial(int numBer) { if (numBer == 0) return numBer; return numBer + recursiveFactorial(numBer - 1); }

  • @javanehmoghavi3954
    @javanehmoghavi3954 10 หลายเดือนก่อน

    excellent, your trainings are awesome

  • @ЭлбекМелибаев
    @ЭлбекМелибаев 2 ปีที่แล้ว +1

    just loved your explanation))

  • @makoto7275
    @makoto7275 3 ปีที่แล้ว +1

    Thank you so much!

  • @dushyantvyas3589
    @dushyantvyas3589 2 ปีที่แล้ว +1

    Can you please make a dedicated video on 'for loop' and 'while loop' in much greater details? such as nested loops, pattern programs using loops (basic to advance level). I'm having hard time with loops especially when it comes to pattern to draw a shapes using loops. I face difficulties behind its code generation from logic.

  • @iirxit
    @iirxit 3 ปีที่แล้ว +1

    You are the best
    Can you make more examples of for loop please 🙏

  • @MrHappyChappyX
    @MrHappyChappyX 4 ปีที่แล้ว +2

    Hey CodeBeuty, total novice here and going through your videos have made the world of code less scary! I do have one question about the for loop, in the lines:
    for (int i = 1; i

    • @robertbruce5513
      @robertbruce5513 4 ปีที่แล้ว +1

      initialization (i=1)-->then it checks the condition(i if the condition satisfies,it executes the statement/statements between the curly braces--> then it goes to the increment/decrement part(here,i++)-->then value of i
      is updated-->checks condition...it goes on and on until the condition is not satisfied or you use break statement. :V

    • @vk2ig
      @vk2ig 3 ปีที่แล้ว +1

      You can think of it this way if you wish - the "for" loop works just like this implementation of a "while" loop:
      int i = 1;
      while (i

  • @ChrisVideosGreek
    @ChrisVideosGreek 3 ปีที่แล้ว

    One day, you HAVE to teach the value outside functions it's pretty good.

  • @darius2955
    @darius2955 ปีที่แล้ว

    Thank you ☺️

  • @Himalayas1921
    @Himalayas1921 3 ปีที่แล้ว

    Thankxxx alot. Explained very well# keep it up.

  • @40wattstudio41
    @40wattstudio41 ปีที่แล้ว

    Any examples of when you would use a factorial in a game or software?

  • @emilianoguillenmedina1066
    @emilianoguillenmedina1066 4 ปีที่แล้ว +3

    regards from México

    • @CodeBeauty
      @CodeBeauty  4 ปีที่แล้ว +4

      Saludos para el México y bienvenido Emiliano! 🤗
      Increasing or decreasing the counter and setting the condition is considered the best practice to end the loop.
      However, there are other ways to terminate the execution of your loop if you really need to use them.
      Among those are break and goto statements, but if you make a habit of using these in large projects, you can find yourself maintaining code that is prone to bugs, very hard to understand (spaghetti code), and difficult to trace the control flow of a program.
      Because of that, I wouldn't encourage using them.
      Each time that you find yourself resorting to one of these in order to solve a problem, you should ask yourself how could you write that code without one of those, because in most cases it can be done.
      With that being said, there is one situation where they can be useful, and that would be for jumping out of deeply-nested loops since that would be often cleaner than using a condition variable and checking it on each level.

  • @clarrisac750
    @clarrisac750 4 ปีที่แล้ว +3

    Wanna ask I noticed that the factorial for number beyond 12 is inaccurate which most probably due to max number of integer is 2^31.How can I modify my code so that it can calculate beyond 12?

    • @CodeBeauty
      @CodeBeauty  4 ปีที่แล้ว +1

      Exactly! The number that you want to store in your int type is too big, so it cannot be stored into an int.
      I have talked about that in this video th-cam.com/video/solufpKPDwY/w-d-xo.html, so you can find more details there
      As far as I know, the long long data-type is the largest built-in integral datatype.
      So you can use unsigned long long int to store longer number and calculate the larger factorial.
      If you need an even bigger number than you'll have to use libs that are designed to work with extremely large numbers :D

    • @emilianoguillenmedina1066
      @emilianoguillenmedina1066 4 ปีที่แล้ว

      I remeber that you can use doble instead int to doble the capacity of your variable, you can try it.

  • @sayedosama4687
    @sayedosama4687 3 ปีที่แล้ว

    god bless you ❤

  • @mahedirony3408
    @mahedirony3408 2 ปีที่แล้ว

    Easy to understand
    take love

  • @yashjadhav6838
    @yashjadhav6838 3 ปีที่แล้ว

    Thanks a lot

  • @TheDora422
    @TheDora422 3 ปีที่แล้ว

    Is the 3rd part (increasing/decreasing)of the For-loop always ignored on the first run? If it would just executed the conditions in the brackets after another ,the inserted number would be always In or decreased before executing the loop

  • @HarderThanCalculus
    @HarderThanCalculus 2 ปีที่แล้ว

    to check for negative numbers I stuck in a little if else statement: if(number

    • @day4834
      @day4834 2 ปีที่แล้ว

      Hi, this removes the negative numbers from the equation:
      #include
      using std::cout;
      using std::cin;
      using std::endl;
      int main() {
      int number, factorial = 1;
      cout number;
      if (number >= 0) {
      if (number == 0)
      cout

  • @ChrisVideosGreek
    @ChrisVideosGreek 3 ปีที่แล้ว

    l mostly use an intializer for i when using for loops :D

  • @tcrawford8430
    @tcrawford8430 4 ปีที่แล้ว

    How can I loop the factorial to adjust to the user input number in my for loop?

  • @mhdjaseem3195
    @mhdjaseem3195 3 ปีที่แล้ว

    thanks, mam💕💖

  • @anthonywilson8366
    @anthonywilson8366 2 ปีที่แล้ว

    How can I increase in increments , do you have a video on that maddam?

  • @trippics8465
    @trippics8465 3 ปีที่แล้ว +1

    Pl.. make a video of find factorial no using recursion.

    • @CodeBeauty
      @CodeBeauty  3 ปีที่แล้ว +1

      I already have that video: th-cam.com/video/MwfvXDfaZeI/w-d-xo.html
      Hope it helps!😃

    • @trippics8465
      @trippics8465 3 ปีที่แล้ว

      @@CodeBeauty Thanks Ma'am.

    • @trippics8465
      @trippics8465 3 ปีที่แล้ว

      @@CodeBeauty Thank You So much dear.

  • @jerseychou4323
    @jerseychou4323 ปีที่แล้ว

    tks

  • @jamieMcSorley-c4i
    @jamieMcSorley-c4i 5 หลายเดือนก่อน

    I noticed if I enter a letter or a symbol, the program immediately runs through the code asking to enter the pin, but doesn't allow a pin to be entered, then the program defaults to "Blocked". Is there a way to debug this? I was thinking of using another if statement

  • @amaulearyan9912
    @amaulearyan9912 3 ปีที่แล้ว

    How can i calculate 100! ? as this programme show 100! = 0 and 20! = in negative ?

  • @findikbabi
    @findikbabi 4 ปีที่แล้ว +2

    I upgraded to code to include the possibilities of the user entering 0 or a negative number you can check it out and give me tips
    int number;
    cout > number;
    int factorial = 1;
    if (number == 0)
    {
    cout

    • @CodeBeauty
      @CodeBeauty  4 ปีที่แล้ว +3

      This will work. Now, here is an idea of how you can do the same thing with less code. How about reducing your code to this:
      int number;
      cout > number;
      int factorial = 1;
      if (number < 0)
      {
      cout = 1; i--)
      {
      factorial = factorial * i;
      }
      cout

    • @findikbabi
      @findikbabi 4 ปีที่แล้ว +2

      CodeBeauty Thank you

  • @lopez5371
    @lopez5371 2 ปีที่แล้ว

    I want the answer to be like for example as " 3!=3*2*1=6"... how can we do this???

  • @ir4kli
    @ir4kli 3 ปีที่แล้ว

    #include
    using namespace std;
    int main(){
    int num,factorial=1;
    cin>>num;
    while(num>0){
    factorial=factorial*num;
    num--;
    }cout

  • @akanguven114
    @akanguven114 ปีที่แล้ว

    Hello, I am entering my info but the book has not been sent to my mail.. Thanks, I am Bosnian :)

  • @simonasulcova8835
    @simonasulcova8835 3 ปีที่แล้ว

    12:41 Can somebody please tell me, how did she do this? Every time I try this it comments like this: /* */. Id be happy for any advice, guys

  • @imnot9923
    @imnot9923 2 ปีที่แล้ว

    Comment for Algor

  • @zakariaaenajjachi2127
    @zakariaaenajjachi2127 3 ปีที่แล้ว

    there is a more better method wich is just do factoriel = number *(number+1)/2

  • @Byynx
    @Byynx ปีที่แล้ว

    For the health of your eyes and overall health i strongly advise you to change the background to a dark color.

  • @omaristaitia5628
    @omaristaitia5628 3 ปีที่แล้ว

    So nice Saldina you look like million Dollar

  • @dorianbs43
    @dorianbs43 2 ปีที่แล้ว

    Thank you so much