#include int main(){ int base,power,result=1; cout "; cin>>base; cout ";...
TRANSCRIPT
![Page 1: #include int main(){ int base,power,result=1; cout "; cin>>base; cout "; cin>>power; for(int i=0;i](https://reader031.vdocuments.site/reader031/viewer/2022032308/56649cfa5503460f949cb637/html5/thumbnails/1.jpg)
![Page 2: #include int main(){ int base,power,result=1; cout "; cin>>base; cout "; cin>>power; for(int i=0;i](https://reader031.vdocuments.site/reader031/viewer/2022032308/56649cfa5503460f949cb637/html5/thumbnails/2.jpg)
• #include<iostream>• #include<conio>• int main(){• int base,power,result=1;• cout<<"Plz enter base --> ";• cin>>base;• cout<<"Plz enter power --> ";• cin>>power;• for(int i=0;i<power;i++)• result=result*base;• cout<<"\nThe result is: "<<result;• getch();• return 0;• }
![Page 3: #include int main(){ int base,power,result=1; cout "; cin>>base; cout "; cin>>power; for(int i=0;i](https://reader031.vdocuments.site/reader031/viewer/2022032308/56649cfa5503460f949cb637/html5/thumbnails/3.jpg)
![Page 4: #include int main(){ int base,power,result=1; cout "; cin>>base; cout "; cin>>power; for(int i=0;i](https://reader031.vdocuments.site/reader031/viewer/2022032308/56649cfa5503460f949cb637/html5/thumbnails/4.jpg)
do-while Loopdo-while Loop• The structure of do-while loop can be
defined as:• do{• statement;• statement;• } while(condition);
![Page 5: #include int main(){ int base,power,result=1; cout "; cin>>base; cout "; cin>>power; for(int i=0;i](https://reader031.vdocuments.site/reader031/viewer/2022032308/56649cfa5503460f949cb637/html5/thumbnails/5.jpg)
Nested LoopsNested Loops• We can use loops inside loop body• Lot of care is needed in this type of
structure• First inner loop complete its iteration
and then control shift to outer one, this process continues till end
![Page 6: #include int main(){ int base,power,result=1; cout "; cin>>base; cout "; cin>>power; for(int i=0;i](https://reader031.vdocuments.site/reader031/viewer/2022032308/56649cfa5503460f949cb637/html5/thumbnails/6.jpg)
• #include<conio>• #include<iostream>• int main(){• for(int i=0;i<5;i++){• for(int j=0;j<5;j++){• cout<<"*";• }• cout<<"\n";• }• getch();• return 0;• }
![Page 7: #include int main(){ int base,power,result=1; cout "; cin>>base; cout "; cin>>power; for(int i=0;i](https://reader031.vdocuments.site/reader031/viewer/2022032308/56649cfa5503460f949cb637/html5/thumbnails/7.jpg)
#include<conio>
#include<iostream>
int main(){
for(int i=1;i<=10;i++){
for(int j=1;j<=i;j++)
cout<<"*";
cout<<endl;
}
getch();
return 0;}
![Page 8: #include int main(){ int base,power,result=1; cout "; cin>>base; cout "; cin>>power; for(int i=0;i](https://reader031.vdocuments.site/reader031/viewer/2022032308/56649cfa5503460f949cb637/html5/thumbnails/8.jpg)
#include<conio>
#include<iostream>
int main(){
for(int i=10;i>=0;i--){
for(int j=1;j<=i;j++)
cout<<"*";
cout<<endl;
}
getch();
return 0;
}
![Page 9: #include int main(){ int base,power,result=1; cout "; cin>>base; cout "; cin>>power; for(int i=0;i](https://reader031.vdocuments.site/reader031/viewer/2022032308/56649cfa5503460f949cb637/html5/thumbnails/9.jpg)
![Page 10: #include int main(){ int base,power,result=1; cout "; cin>>base; cout "; cin>>power; for(int i=0;i](https://reader031.vdocuments.site/reader031/viewer/2022032308/56649cfa5503460f949cb637/html5/thumbnails/10.jpg)
ReviewReview• Input and Output• Variable(type,space,range)• Operators
Arithmetic,Relational,Logical,Ternary,Unary operators
• Selective Flow Single,Double,Multiple
• Iterative Flow while loop, for loop, do-while loop
![Page 11: #include int main(){ int base,power,result=1; cout "; cin>>base; cout "; cin>>power; for(int i=0;i](https://reader031.vdocuments.site/reader031/viewer/2022032308/56649cfa5503460f949cb637/html5/thumbnails/11.jpg)
FunctionsFunctions• #include<iostream>• #include<iostream>• int main(){• clrscr();• cout<<“Good Luck”;• getch();• return 0• }
![Page 12: #include int main(){ int base,power,result=1; cout "; cin>>base; cout "; cin>>power; for(int i=0;i](https://reader031.vdocuments.site/reader031/viewer/2022032308/56649cfa5503460f949cb637/html5/thumbnails/12.jpg)
Program Writing StyleProgram Writing StyleStructured Approach• Action oriented approach• Consist of blocks(function)Object Oriented Approach• Consist of classes• Class is an type
object(action+qualities)
![Page 13: #include int main(){ int base,power,result=1; cout "; cin>>base; cout "; cin>>power; for(int i=0;i](https://reader031.vdocuments.site/reader031/viewer/2022032308/56649cfa5503460f949cb637/html5/thumbnails/13.jpg)
User-defined FunctionsUser-defined Functions return-value-type function-name(parameter-list)
{ declarations and statements}• Return-Type: No(void) return or type• Function-name: Any(identifier rules)• Parameter: No(void) or no. of
parameters with types
![Page 14: #include int main(){ int base,power,result=1; cout "; cin>>base; cout "; cin>>power; for(int i=0;i](https://reader031.vdocuments.site/reader031/viewer/2022032308/56649cfa5503460f949cb637/html5/thumbnails/14.jpg)
Simple FunctionSimple Function void line(){ for(int i=0;i<45;i++) cout<<“*”; cout<<endl; }
No Return Name No Parameter
![Page 15: #include int main(){ int base,power,result=1; cout "; cin>>base; cout "; cin>>power; for(int i=0;i](https://reader031.vdocuments.site/reader031/viewer/2022032308/56649cfa5503460f949cb637/html5/thumbnails/15.jpg)
Using FunctionUsing Function• Three important thing should be in
min when we use functions in main function
1. Function Definition: It is just body of function which is
below the main2. Function declaration3. Function call
![Page 16: #include int main(){ int base,power,result=1; cout "; cin>>base; cout "; cin>>power; for(int i=0;i](https://reader031.vdocuments.site/reader031/viewer/2022032308/56649cfa5503460f949cb637/html5/thumbnails/16.jpg)
Using FunctionUsing Function
Function Definition
Function Call
Function Declaration
![Page 17: #include int main(){ int base,power,result=1; cout "; cin>>base; cout "; cin>>power; for(int i=0;i](https://reader031.vdocuments.site/reader031/viewer/2022032308/56649cfa5503460f949cb637/html5/thumbnails/17.jpg)
![Page 18: #include int main(){ int base,power,result=1; cout "; cin>>base; cout "; cin>>power; for(int i=0;i](https://reader031.vdocuments.site/reader031/viewer/2022032308/56649cfa5503460f949cb637/html5/thumbnails/18.jpg)
• #include<conio>• #include<iostream>• void line();• void hash();• void dash();• int main(){• dash();• for(int i=0;i<5;i++)• line();• dash();• for(int i=0;i<5;i++)• hash();• getch();• return 0;• }
![Page 19: #include int main(){ int base,power,result=1; cout "; cin>>base; cout "; cin>>power; for(int i=0;i](https://reader031.vdocuments.site/reader031/viewer/2022032308/56649cfa5503460f949cb637/html5/thumbnails/19.jpg)
• void line(){• for(int i=0;i<45;i++)• cout<<"*";• cout<<endl;• }• void hash(){• for(int i=0;i<45;i++)• cout<<"#";• cout<<endl;• }• void dash(){• for(int i=0;i<45;i++)• cout<<"-";• cout<<endl;• }
![Page 20: #include int main(){ int base,power,result=1; cout "; cin>>base; cout "; cin>>power; for(int i=0;i](https://reader031.vdocuments.site/reader031/viewer/2022032308/56649cfa5503460f949cb637/html5/thumbnails/20.jpg)
![Page 21: #include int main(){ int base,power,result=1; cout "; cin>>base; cout "; cin>>power; for(int i=0;i](https://reader031.vdocuments.site/reader031/viewer/2022032308/56649cfa5503460f949cb637/html5/thumbnails/21.jpg)
Passing Values To functionsPassing Values To functions• We can pass any type of value to
function• We have to define the data type of
the values • During function call we send on those
values which a function can accept
![Page 22: #include int main(){ int base,power,result=1; cout "; cin>>base; cout "; cin>>power; for(int i=0;i](https://reader031.vdocuments.site/reader031/viewer/2022032308/56649cfa5503460f949cb637/html5/thumbnails/22.jpg)
Passing Values To functionsPassing Values To functions
![Page 23: #include int main(){ int base,power,result=1; cout "; cin>>base; cout "; cin>>power; for(int i=0;i](https://reader031.vdocuments.site/reader031/viewer/2022032308/56649cfa5503460f949cb637/html5/thumbnails/23.jpg)
ProblemProblem
Write a function which takes three integers as parameters and display the smallest integer
![Page 24: #include int main(){ int base,power,result=1; cout "; cin>>base; cout "; cin>>power; for(int i=0;i](https://reader031.vdocuments.site/reader031/viewer/2022032308/56649cfa5503460f949cb637/html5/thumbnails/24.jpg)
• #include<conio>• #include<iostream>• void small(int,int,int );• int main(){• small(123,135,140);• getch();• return 0;• }• void small(int a,int b,int c){• int small=a;• if(b<small)• small=b;• if(c<small)• small=c;• cout<<"Samll is:"<<small<<endl;• }