Course Title: CP - LAB: Bahria University, Islamabad
Course Title: CP - LAB: Bahria University, Islamabad
Lab Journal: 08
Objectives:
Functions
Tools Used:
Procedure/Program:
#include<iostream>
#include<conio.h>
using namespace std;
int Swap (int* a, int* b, int* c);
int main ()
{
int a, b, c; a = 5, b = 3, c = 4 ;
cout << "Enter value of a:" << a << endl;
cout << "Enter value of b:" << b << endl;
cout << "Enter value of c:" << c << endl;
Swap(&a, &b, &c);
return 0;
}
Result/Output:
Task # 2:
Write a function called zero Smaller (int&,int&) that will be passed two int arguments by
reference and then sets the smaller of the two numbers to 0. Write main() to display changed
values.
Procedure/Program:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int x, y;
cout << "Enter first number : ";
cin >> x;
cout << "Enter second number : ";
cin >> y;
zero_small(x, y);
cout << "First number is : " << x;
cout << "\nSecond number is : " << y;
return 0;
}
Result/Output:
Task # 3:
Write a function change Value() which takes one int argument. Check the value if it is even then
add 13 in the value and if it is odd do not change anything in it. Display the changed value in
main().
Procedure/Program:
#include<iostream>
#include<conio.h>
using namespace std;
int value(int);
int main()
{
int a;
cout << "Enter a number: ";
cin >> a;
int r = changevalue(a);
}
int value(int a)
{
if (a % 2 == 0)
{
cout << "Number is even." << endl;
int r = a + 13;
cout << "changed value is " << r << endl;
}
else
cout << "Number is odd." << endl;
return a;
}
Result/Output:
Even:
ODD: