The Big Master

Library function

In C++, a library function refers to a function that is part...

In C++, a library function refers to a function that is part of a pre-existing library of code provided by the C++ standard library or a third-party library. These functions are designed to perform specific tasks or provide specific functionality and can be used by programmers to achieve desired operations without having to write the code from scratch.

Program to Calculate Square Root:

#include <iostream>
#include <cmath>
using namespace std;
using namespace std ;
int main() {
    double num;
    cout << "Enter a number: ";
    cin >> num;
    double squareRoot = sqrt(num);
    cout << "Square root of " << num << " is " << squareRoot << endl;
    return 0;
}

 

Program to Calculate Absolute Value:

#include <iostream>
#include <cstdlib>
using namespace std ;
int main() {
    int num;
    cout << "Enter a number: ";
    cin >> num;
    int absoluteValue = abs(num);
    cout << "Absolute value of " << num << " is " << absoluteValue << endl;
    return 0;
}

 

Program to Find Maximum of Two Numbers:

using namespace std ;
#include <iostream>
#include <algorithm>
int main() {
    int num1, num2;
    cout << "Enter two numbers: ";
    cin >> num1 >> num2;
    int maxNum = max(num1, num2);
    cout << "Maximum of " << num1 << " and " << num2 << " is " << maxNum << endl;
    return 0;
}

 

Program to Generate Random Numbers:

#include <iostream>
#include <cstdlib>
#include <ctime>
int main() {
    srand(time(0));  // Seed the random number generator with current time
    int randomNum = rand() % 100;  // Generate a random number between 0 and 99
    cout << "Random number: " << randomNum << endl;
    return 0;
}