Posts

PROGRAM TO PERFORM FUNCTION OVERLOADING

Program to perform function overloading: Code: #include<iostream.h> #include<conio.h> void multiply(int x) { cout <<"the value is"<<"\t"<<x*3<<"\n"; } void multiply(int x,int y) { cout<<"the value is"<<"\t"<<x*y<<"\n"; } void main() { clrscr(); multiply(3); multiply(3,5); getch(); } Output: the value is 9 the value is 15

PROGRAM TO PERFORM INLINE FUNCTION

Program to perform inline function: Code: #include<iostream.h> #include<conio.h> inline float convert_feet(int x) { return x*4; } void main() { clrscr(); int inches; cin>>inches; cout<<"the value is"<<"\t"<<convert_feet(inches); getch(); } Output: 5 the value is 20

PROGRAM TO PERFORM RRETURN BY REFERENCE

Program to perform return by reference: Code: #include<iostream.h> #include<conio.h> void main() { clrscr(); int &max(int &,int &); int a,b; cin>>a>>b; max(a,b)=-1; cout<<a<<"\t"<<b; } int &max(int &x,int &y) { if(x>y) return x; else return y; } Output: 3 4 3     -1

PROGRAM TO PERFORM CALL BY REFERENCE

Pr ogram to perform call by reference: Code: #include<iostream.h> #include<conio.h> void exchange(int &a,int &b) { int c; c=a; a=b; b=c; } void main() { clrscr(); int a,b; cin>>a>>b; cout<<"\t"<<"\nbefore function call\t"; cout<<a<<"\t"<<b; exchange(a,b); cout<<"\t"<<"\nafter function call\t"; cout<<a<<"\t"<<b; getch(); } Output: 3 5 before function call 3 5 after function call 5 3

PROGRAM TO PERFORM CALL BY VALUE

Program to perform call by value : Code: #include<iostream.h> #include<conio.h> void exchange(int a,int b) { int c; c=a; a=b; b=c; } void main() { clrscr(); int a,b; cin>>a>>b; cout<<"\t"<<"\nbefore function call\t"; cout<<a<<"\t"<<b; exchange(a,b); cout<<"\t"<<"\nafter function call\t"; cout<<a<<"\t"<<b; getch(); } Output:  3 5 before function call 3 5 after function call 5 3

PRINT IF PREVIOUS IS SMALLER

Image