c++ Lecture 14 In Urdu
For loop practice
#include
<iostream>
#include<conio.d>
void main()
{
int i, n, f= 1;
cout<<"Enter a number: ";
cin>>n;
for (i = 1; i <= n; i++)
{
f *= i; // f = f * I
}
cout<< "Factorial of "<<n<<" = "<<f;
getch();
}
#include<conio.d>
void main()
{
int i, n, f= 1;
cout<<"Enter a number: ";
cin>>n;
for (i = 1; i <= n; i++)
{
f *= i; // f = f * I
}
cout<< "Factorial of "<<n<<" = "<<f;
getch();
}
·
Es me hm ne 3 varible liye int type k.
·
I for looping n for input from user and f fort factorial.
·
Ur f ko 1 se initialize kia
·
Per usr se input le jo n me save ho ge
·
Es kl bad loop start ho ge I o 1 se inityalize kia
·
Es k bad condition check ho ge I less hai ya erqual hai n se farz kary
user ne 5 input liya hai
·
Ha chota hai es k bad pehly 1 add ho jay ga n k sat 2 ho jay ga
·
Body me ga execute hop ga
·
Per loop py jay ga condition check ho ge true hai 2 bara hai per body me aye ga body execute ho ge
·
Es tarha hota rahy ga jab 5 se bara ho jai I to flase ho k bahar aye ga
body se
·
Ur output aye ge
Enter a positive
integer: 5
Factorial of 5 = 120
#include<iostream>
#include<conio.h>
void main()
{
int a;
cout<<"Enter the Number :";
cin>>a;
for (int c = 1; c<= a; c++)
#include<conio.h>
void main()
{
int a;
cout<<"Enter the Number :";
cin>>a;
for (int c = 1; c<= a; c++)
{
cout<<"Execute "<<c<<" time"<<endl;
}
getch();
}
cout<<"Execute "<<c<<" time"<<endl;
}
getch();
}
Write run approch
Enter the Number :5
Execute 1 time
Execute 2 time
Execute 3 time
Execute 4 time
Execute 5 time
No comments:
Post a Comment