LAB 9 .docx - CSL-113 Computer Programming Lab Semester BS CS – 01 Exercise 1 Write a C Program that calculates the power of a base by a user defined

# LAB 9 .docx - CSL-113 Computer Programming Lab Semester BS...

• 7

This preview shows page 1 - 3 out of 7 pages.

CSL-113: Computer Programming Lab Semester BS CS – 01 Exercise 1 Write a C++ Program that calculates the power of a base by a user defined function as follows: Take the power and the base from the user in the main function. Calcuate the power of the base in a user defined function “MY_POWER” by passing power and base from the main() to the MY_POWER function. Calculated value must return from the function to the main and display there. Print the result as follows: Program #include <iostream> #include <iomanip> using namespace std; int MY_POWER( int x , int y ) { int result = 1; for ( int i = 1; i <= y ; i++) { result *= x ; } return result; } int main() { int base, power, result; cout << setfill( '=' ) << setw(40) << "=" << endl; cout << "enter any base: " ; cin >> base; cout << setfill( '=' ) << setw(40) << "=" << endl; cout << "enter power: " ; cin >> power; cout << setfill( '=' ) << setw(40) << "=" << endl; result = MY_POWER(base, power); cout << "Result for power " << power << " of base " << base << " = " << result << endl; cout << setfill( '=' ) << setw(40) << "=" << endl; system( "pause" ); return 0; } Output Department of Computer Sciences Page: 1/7 Semester BSCS 01 CSL-113: Computer Programming Lab Lab 09: Function-II
CSL-113: Computer Programming Lab Semester BS CS – 01 Exercise 2 Write a C++ Program that perform following task: Generate three random numbers ranged from 1 to 100. Calculate average of three numbers using a function avrg(int, int, int, int&). Calculate standard deviation and variance of three numbers.

#### You've reached the end of your free preview.

Want to read all 7 pages?

• Summer '19

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern