Library Functions [SET – 1]
#include <iostream> #include <cmath> using namespace std; int main() { double principal, rate, time, compoundInterest; cout << "Enter Principal: "; cin >> principal; cout << "Enter Rate: "; cin >> rate; cout << "Enter Time: "; cin >> time; compoundInterest = principal * pow((1 + rate / 100), time) - principal; cout << "Compound Interest: " << compoundInterest; return 0; }
#include <iostream> #include <cmath> using namespace std; int main() { double a, b, c, s, area; cout << "Enter three sides of the triangle: "; cin >> a >> b >> c; s = (a + b + c) / 2; area = sqrt(s * (s - a) * (s - b) * (s - c)); cout << "Area of the triangle: " << area; return 0; }
#include <iostream> #include <cctype> using namespace std; int main() { char ch; cout << "Enter a character: "; cin >> ch; if (isalpha(ch)) { cout << ch << " is an alphabet."; } else if (isdigit(ch)) { cout << ch << " is a digit."; } else { cout << ch << " is a special character."; } return 0; }
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() { srand(time(0)); // Seed for random number generator int randomNum = 10 + rand() % 91; // Generate a number between 10 and 100 cout << "Random Number: " << randomNum; return 0; }
#include <iostream> #include <cctype> using namespace std; int main() { char ch; cout << "Enter a letter: "; cin >> ch; if (islower(ch)) { ch = toupper(ch); } cout << "Uppercase Letter: " << ch; return 0; }
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() { srand(time(0)); int number = 1 + rand() % 100; // Random number between 1 and 100 int guess, attempts = 0; cout << "Guess the number between 1 and 100: " << endl; do { cout << "Enter your guess: "; cin >> guess; attempts++; if (guess < number) { cout << "Too low!" << endl; } else if (guess > number) { cout << "Too high!" << endl; } else { cout << "Congratulations! You guessed the number in " << attempts << " attempts." << endl; } } while (guess != number); return 0; }