0% found this document useful (0 votes)
55 views4 pages

C++ Input and Basic Operations

The document contains code for several C++ programs that demonstrate functions. The first program shows a swap function that exchanges the values of two integers passed by reference. The second program defines inline functions to sum and multiply five integers input by the user. The third program defines inline functions for basic math operations on two integers input by the user. The fourth program defines a function to return the largest of two integers input by the user.

Uploaded by

Trick .2G
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views4 pages

C++ Input and Basic Operations

The document contains code for several C++ programs that demonstrate functions. The first program shows a swap function that exchanges the values of two integers passed by reference. The second program defines inline functions to sum and multiply five integers input by the user. The third program defines inline functions for basic math operations on two integers input by the user. The fourth program defines a function to return the largest of two integers input by the user.

Uploaded by

Trick .2G
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Act 9 Set 1-1

#include<iostream>
using namespace std;

void swap(int* a, int* b)


{
int temp;
temp = *a;
*a = *b;
*b = temp;
}

int main()
{
int num1, num2;
cout << "Enter 1st numer: ";
cin >> num1;
cout << "Enter 2nd number: ";
cin >> num2;

cout << "\nBefore swapping" << endl;


cout << "a = " << num1 << " || " << "b = " << num2 << endl;

swap(&num1, &num2);

cout << "\nAfter Swapping" << endl;


cout << "a = " << num1 << " || " << "b = " << num2 << endl;

return 0;
}
Act 9 Set 1-2

#include<iostream>
using namespace std;

inline int sum(int a, int b, int c, int d, int e)


{
return(a + b + c + d + e);
}

inline int mul(int a, int b, int c, int d, int e)


{
return(a * b * c * d * e);
}

int main()
{
int num1, num2, num3, num4, num5;

cout << "Enter 1st number :: ";


cin >> num1;
cout << "Enter 2nd number :: ";
cin >> num2;
cout << "Enter 3rd number :: ";
cin >> num3;
cout << "Enter 4th number :: ";
cin >> num4;
cout << "Enter 5th number :: ";
cin >> num5;

cout << "\nSum of 5 Numbers [ " << num1 << "+" << num2 << "+" << num3 << "+" << num4 << "+" << num5 << " ] = "
<< sum(num1, num2, num3, num4, num5) << "\n";
cout << "Product of 5 Numbers [ " << num1 << "*" << num2 << "*" << num3 << "*" << num4 << "*" << num5 << " ] = "
<< mul(num1, num2, num3, num4, num5) << "\n";

return 0;
}
Act 9 Set 2-1

#include<iostream>
using namespace std;

inline int sum(int a, int b)


{
return(a + b);
}

inline int diff(int a, int b)


{
return(a - b);
}

inline int mul(int a, int b)


{
return(a * b);
}

int main()
{
int num1, num2;

cout << "Enter 1st number :: ";


cin >> num1;
cout << "Enter 2nd number :: ";
cin >> num2;

cout << "\nAddition of two Numbers [ " << num1 << " + " << num2 << " ] = " << sum(num1, num2) << "\n";
cout << "Subtraction of two Numbers [ " << num1 << " - " << num2 << " ] = " << diff(num1, num2) << "\n";
cout << "Multiplication of two Numbers [ " << num1 << " * " << num2 << " ] = " << mul(num1, num2) << "\n";

return 0;
}
Act 9 Set 2-2

#include<iostream>
using namespace std;

inline int Largest(int a, int b)


{
int ret;
ret = (a > b) ? a : b;
return(ret);
}

int main()
{
int num1, num2;

cout << "Enter 1st number :: ";


cin >> num1;
cout << "Enter 2nd number :: ";
cin >> num2;

cout << "\nLargest of two numbers [ " << num1 << ", " << num2 << " ] is :: " << Largest(num1, num2) << endl;

return 0;
}

You might also like