Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
8 views2 pages

Basic CPP Practice Questions With Solutions

The document contains basic C++ practice questions with solutions, including printing personal details, performing arithmetic operations, swapping numbers with and without a temporary variable, and checking if a number is even or odd. Each example is accompanied by a code snippet demonstrating the implementation. These exercises are designed to help beginners practice fundamental C++ programming concepts.

Uploaded by

Top up Central
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)
8 views2 pages

Basic CPP Practice Questions With Solutions

The document contains basic C++ practice questions with solutions, including printing personal details, performing arithmetic operations, swapping numbers with and without a temporary variable, and checking if a number is even or odd. Each example is accompanied by a code snippet demonstrating the implementation. These exercises are designed to help beginners practice fundamental C++ programming concepts.

Uploaded by

Top up Central
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/ 2

Basic C++ Practice Questions with Solutions

1. Print personal details

#include <iostream>
using namespace std;
int main() {
cout << "Name: John Doe\n";
cout << "Roll Number: 123456\n";
cout << "Department: CSE\n";
return 0;
}

2. Basic arithmetic operations

#include <iostream>
using namespace std;
int main() {
int a = 10, b = 5;
cout << "Addition: " << a + b << endl;
cout << "Subtraction: " << a - b << endl;
cout << "Multiplication: " << a * b << endl;
cout << "Division: " << a / b << endl;
return 0;
}

3. Swap numbers using temp

#include <iostream>
using namespace std;
int main() {
int a = 5, b = 10, temp;
temp = a;
a = b;
b = temp;
cout << "a: " << a << ", b: " << b << endl;
return 0;
}

4. Swap numbers without temp

#include <iostream>
using namespace std;
int main() {
int a = 5, b = 10;
a = a + b;
b = a - b;
a = a - b;
cout << "a: " << a << ", b: " << b << endl;
return 0;
}

5. Check even or odd

#include <iostream>
using namespace std;
int main() {
int num;
cout << "Enter a number: ";
cin >> num;
if (num % 2 == 0)
cout << "Even\n";
else
cout << "Odd\n";
return 0;
}

You might also like