C++ Language Programs: Program 2
C++ Language Programs: Program 2
Program 2
C++
#include <iostream>
int main() {
string name;
cout << "Hello, " << name << "!" << endl;
return 0;
#include <iostream>
int main() {
cout << "The area of the rectangle is: " << area << endl;
return 0; }
4. write a program to input speed and time to calculate distance and then
print it.
C++
#include <iostream>
// Calculate distance
cout << "Distance traveled: " << distance << " kilometers" << endl;
return 0;
#include <iostream>
int main() {
cout << "The sum of " << num1 << " and " << num2 << " is: " << sum << endl;
return 0;
Write a program that displays the following triangle pattern on the screen:
#include<iostream>
int main(){
cout<<" *"<<endl;
cout<<" ***"<<endl;
cout<<" *****"<<endl;
cout<<" ********"<<endl;
return 0;
int main() {
cout << "Floating-point Division (x / y): " << (x / y) << endl; // Output: 3.3333...
return 0;
int main() {
double x = 10, y = 3;
cout << "Floating-point Division (x * y): " << (x *y) << endl;
return 0;
int main() {
int number;
if (number >=50) {
}else{
return 0;
}
int main() {
int number;
if (number > 0) {
return 0;
int main() {
int x = 5;
cout << "Postfix: " << x++ << endl; // Outputs 5, then x becomes 6
cout << "Prefix: " << ++x << endl; // x becomes 7, then outputs 7
return 0;
13. Program
# include <iostream>
int main() {
int x = 5;
cout << "Postfix: " << x-- << endl; // Outputs 5, then x becomes 6
cout << "Prefix: " << --x << endl; // x becomes 7, then outputs 7
return 0;}
int main() {
int num = 1;
num++;
return 0;
Output:
1 2 3 4 5 6 7 8 9 10