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

preview_player
Показать описание
What is for loop and how is it used?
What is the difference between while, do while and for loop?
In this video I'll explain how and when is for loop used on an example of calculating the factorial of a number.

📚 Learn how to solve problems and build projects with these Free E-Books ⬇️

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.

Contents:
00:00 - Intro
02:19 - What is the difference between while, do while and for loops?

Related videos:

Follow me on other platforms:

*******CODE IS IN THE COMMENTS*******
Рекомендации по теме
Комментарии
Автор

📚 Learn how to solve problems and build projects with these Free E-Books ⬇️
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 <iostream>
using namespace std;

void main()
{
//The factorial of a number

int number;
cout << "Number: ";
cin >> number;

int factorial = 1;

//6!=1*2*3*4*5*6=720
//for (int i = 1; i <= number; i++) {
// factorial = factorial * i;
//}

//6!=6*5*4*3*2*1=720
for (int i = number; i >= 1; i--) {
factorial = factorial * i;
}

cout << number << "!=" << factorial;

system("pause>0");
}

CodeBeauty
Автор

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

angietodaro
Автор

You are an excellent teacher! Thank you very much!

williamwelmans
Автор

Ur teaching is so beautiful 🤩
Just like

himanshugaikwad
Автор

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

venkateshnayak
Автор

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 👍

lukachilukusha
Автор

excellent, your trainings are awesome

javanehmoghavi
Автор

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.

dushyantvyas
Автор

You are the best

Can you make more examples of for loop please 🙏

iirxit
Автор

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.

Nishanths
Автор

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?

onetwo-dicv
Автор

Thankxxx alot. Explained very well# keep it up.

Himalayas
Автор

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

wattstudio
Автор

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 <= number; i++) {
factorial = factorial * i;
}

How come the program will disregard the i++ until it has completed the coding that has been placed? Is that just how for loops work, do they always do what's in the third semi-colon after completing the task?

MrHappyChappyX
Автор

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

ChrisVideosGreek
Автор

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

ChrisVideosGreek
Автор

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

tankrides
Автор

regards from México <3, i have a question.
Can I put anything in the thirt part of the parenthesis of the for loop (in this case "i--") to break it ??? like more lines of code or something else to make false the codition and break the loop or its absolutely neccesary to increase or decrease the asigned variable of the loop (in this case "i") to break it???

emilianoguillenmedina
Автор

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

TheDora
Автор

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?

clarrisac