Programming Lab
Programming Lab
Write a C++ program that takes an array of integers as input and finds the maximum element
#include <iostream>
#include <vector>
int maxPosition = 0;
maxElement = arr[i];
maxPosition = i;
int main() {
cout << "The maximum element is: " << maxElement.first << endl;
cout << "Its position in the array is: " << maxElement.second << endl;
return 0;
2.Write a C++ program that takes a string as input and outputs the reversed version of the
string. Forexample, if the input is "hello," the program should output "olleh".
#include <iostream>
#include <string>
reversed += input[i];
return reversed;
int main() {
string input;
return 0;
3.Write a C++ program that defines a function to calculate and return the sum of two numbers.
The program should take input from the user, call the function, and then output the result.
#include <iostream>
return a + b;
int main() {
cout << "The sum is: " << result << endl;
return 0;
4.Create a C++ program that uses a pointer to calculate the square of a given number. The program
should take input from the user, calculate the square using a function with a pointer, and then output
the result
#include <iostream>
int main() {
int number;
cout << "Hey, what number would you like to calculate the square of? ";
calculateSquare(&number);
cout << "The square of the number is: " << number <<endl;