Basics Programs
Basics Programs
Ans. (Define a maximum variable which will store the maximum in each
iteration)
#include
using namespace std;
int main() {
int arr[5] = { 1, 2, 5, 4, 3 };
int max = 0;
for(int i = 0;i<5;i++)
{
if(max < arr[i])
max = arr[i];
}
cout<<max<<endl;
return 0;
}
2. #include
3. using namespace std;
4. int main() {
5. int number1 = 145;
6. int number2 = 200;
7. cout<<number1<<" "<<number2<<endl;
8. number1 = number1 + number2;
9. number2 = number1 - number2;
10. number1 = number1 - number2;
11. cout<<number1<<" "<<number2<<endl;
12. return 0;
}
Output:
145 200
200 145
// Main function
int main()
{
cout << test(1, 2) << endl; // Output the result of test function
with arguments 1 and 2
cout << test(3, 2) << endl; // Output the result of test function
with arguments 3 and 2
cout << test(2, 2) << endl; // Output the result of test function
with arguments 2 and 2
return 0; // Return 0 to indicate successful execution of the
program
3
5
12
#include <iostream> // Including input/output stream library
#include <string> // Including string library for string manipulation
using namespace std; // Using the standard namespace
int main()
{
cout << "Original string: w3resource"; // Displaying the original string
cout << "\nReverse string: " << reverse_string("w3resource"); // Displaying the reversed string
int main()
{
// current date and time in current system using time_t data type
time_t current_dt = time(0); // Get the current system time in
seconds since epoch (Jan 1, 1970)