Case 1: C++
#include <iostream>
int main() {
std::cout << "Hello, Case 1!";
return 0;
}
Explanation for Case 1:
- The
#include <iostream>
directive includes the input/output stream library for C++. - The
int main()
function is the entry point of the program. std::cout << "Hello, Case 1!";
outputs the string "Hello, Case 1!" to the console.return 0;
indicates successful program termination to the operating system.
Case 2: C++
#include <iostream>
int main() {
int x = 5;
int y = 7;
int sum = x + y;
std::cout << "The sum of " << x << " and " << y << " is " << sum;
return 0;
}
Explanation for Case 2:
- The
#include <iostream>
directive includes the input/output stream library for C++. - The
int main()
function is the entry point of the program. int x = 5;
declares and initializes an integer variable x
with the value 5.int y = 7;
declares and initializes an integer variable y
with the value 7.int sum = x + y;
calculates the sum of x
and y
and stores it in the variable sum
.std::cout << "The sum of " << x << " and " << y << " is " << sum;
outputs the sum of x
and y
to the console.return 0;
indicates successful program termination to the operating system.