0% found this document useful (0 votes)
4 views

10C++ Programs class xi.

The document contains a series of C++ programs that demonstrate basic programming concepts such as printing messages, performing arithmetic operations, swapping numbers, finding the greatest number, generating multiplication tables, and checking the sign of a number. Each program includes code snippets, expected outputs, and user prompts for input. The examples illustrate fundamental programming techniques suitable for beginners.

Uploaded by

piyushdey0830
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

10C++ Programs class xi.

The document contains a series of C++ programs that demonstrate basic programming concepts such as printing messages, performing arithmetic operations, swapping numbers, finding the greatest number, generating multiplication tables, and checking the sign of a number. Each program includes code snippets, expected outputs, and user prompts for input. The examples illustrate fundamental programming techniques suitable for beginners.

Uploaded by

piyushdey0830
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

### 1.

Program to Print "Hello World"


```cpp
#include <iostream>
using namespace std;

int main() {
cout << "Hello World";
return 0;
}
```
**Output:**
```
Hello World
```

### 2. Program to Print an Integer Value


```cpp
#include <iostream>
using namespace std;

int main() {
int a;
cout << "Enter an integer: ";
cin >> a;

1
cout << "The integer is: " << a;
return 0;
}
```
**Output:**
```
Enter an integer: 10
The integer is: 10
```

### 3. Program to Add Two Numbers


```cpp
#include <iostream>
using namespace std;

int main() {
int a, b, sum;
cout << "Enter the first number: ";
cin >> a;
cout << "Enter the second number: ";
cin >> b;
sum = a + b;
cout << "The sum of the two numbers is: " << sum;
return 0;

2
```
**Output:**
```
Enter the first number: 10
Enter the second number: 20
The sum of the two numbers is: 30
```

### 4. Program to Subtract Two Numbers


```cpp
#include <iostream>
using namespace std;

int main() {
int a, b, sub;
cout << "Enter the first number: ";
cin >> a;
cout << "Enter the second number: ";
cin >> b;
sub = a - b;
cout << "The subtraction of the two numbers is: " << sub;
return 0;

}
```
**Output:**

3
```
Enter the first number: 10
Enter the second number: 20
The subtraction of the two numbers is: -10
```

### 5. Program to Multiply Two Numbers


```cpp
#include <iostream>
using namespace std;

int main() {
int a, b, mul;
cout << "Enter the first number: ";
cin >> a;
cout << "Enter the second number: ";
cin >> b;
mul = a * b;
cout << "The multiplication of the two numbers is: " << mul;
return 0;

}
```
**Output:**
```
Enter the first number: 10

4
Enter the second number: 20
The multiplication of the two numbers is: 200
```

### 6. Program to Divide Two Numbers


```cpp
#include <iostream>
using namespace std;

int main() {
int a, b, div;
cout << "Enter the first number: ";
cin >> a;
cout << "Enter the second number: ";
cin >> b;
if (b != 0) {

div = a / b;
cout << "The division of the two numbers is: " << div;
} else {
cout << "Cannot divide by zero.";
}
return 0;
}
```
**Output:**

5
```
Enter the first number: 20
Enter the second number: 10
The division of the two numbers is: 2
```

### 7. Program to Swap Two Numbers Using a Third Variable


```cpp
#include <iostream>
using namespace std;

int main() {
int a, b, c;
cout << "Enter the first number: ";
cin >> a;
cout << "Enter the second number: ";
cin >> b;
c = a;
a = b;
b = c;
cout << "First number is: " << a << endl;
cout << "Second number is: " << b;
return 0;

}
```

6
**Output:**
```
Enter the first number: 12
Enter the second number: 13
First number is: 13
Second number is: 12
```

### 8. Program to Find the Greatest Number Among Two Numbers


```cpp
#include <iostream>
using namespace std;

int main() {
int a, b;
cout << "Enter the first number: ";
cin >> a;
cout << "Enter the second number: ";
cin >> b;
if (a > b) {
cout << "The greatest number is: " << a;
} else {
cout << "The greatest number is: " << b;
}
return 0;

7
}
```
**Output:**
```
Enter the first number: 12
Enter the second number: 13
The greatest number is: 13
```

### 9. Program to Print the Multiplication Table of a Number


```cpp
#include <iostream>
using namespace std;

int main() {
int num;
cout << "Enter a number: ";
cin >> num;
cout << "Multiplication table of " << num << ":\n";
for (int i = 1; i <= 10; i++) {

cout << num << " * " << i << " = " << num * i << endl;
}
return 0;
}
```

8
**Output:** ``` Enter a
number: 8 Multiplication
table of 8: 8 * 1 = 8
8 * 2 = 16
8 * 3 = 24
8 * 4 = 32
8 * 5 = 40
8 * 6 = 48
8 * 7 = 56
8 * 8 = 64
8 * 9 = 72
8 * 10 = 80
```

### 10. Program to Check Whether a Number is Positive, Negative, or Zero


```cpp
#include <iostream>
using namespace std;

int main() {
int num;
cout << "Enter a number: ";
cin >> num;

9
if (num > 0) {
cout << "The number is positive.";
} else if (num < 0) {
cout << "The number is negative.";
} else {
cout << "The number is zero.";
}
return 0;
}
```
**Output:**
```
Enter a number: 10
The number is positive.
```

10

You might also like