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

C++_Programming_Questions

The document contains a series of C++ programming questions and their corresponding answers. It includes programs for printing 'Hello, World!', adding two numbers, checking if a number is even or odd, and displaying the day of the week using a switch statement. Each program is accompanied by its source code.

Uploaded by

mosesmainam017
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)
5 views

C++_Programming_Questions

The document contains a series of C++ programming questions and their corresponding answers. It includes programs for printing 'Hello, World!', adding two numbers, checking if a number is even or odd, and displaying the day of the week using a switch statement. Each program is accompanied by its source code.

Uploaded by

mosesmainam017
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

C++ Programming Questions and Answers

1. Write a C++ program to print 'Hello, World!' on the screen.


#include <iostream>
using namespace std;
int main() {
cout << "Hello, World!" << endl;
return 0;
}

2. Write a C++ program to add two numbers entered by the user.


#include <iostream>
using namespace std;
int main() {
int num1, num2, sum;
cout << "Enter two numbers: ";
cin >> num1 >> num2;
sum = num1 + num2;
cout << "Sum = " << sum << endl;
return 0;
}

3. Write a C++ program to check if a number is even or odd.


#include <iostream>
using namespace std;
int main() {
int num;
cout << "Enter a number: ";
cin >> num;
if (num % 2 == 0)
cout << num << " is even." << endl;
else
cout << num << " is odd." << endl;
return 0;
}

4. Write a C++ program to display the day of the week using a switch statement.
#include <iostream>
using namespace std;
int main() {
int day;
cout << "Enter a number (1-7): ";
cin >> day;
switch (day) {
case 1: cout << "Monday"; break;
case 2: cout << "Tuesday"; break;
case 3: cout << "Wednesday"; break;
case 4: cout << "Thursday"; break;
case 5: cout << "Friday"; break;
case 6: cout << "Saturday"; break;
case 7: cout << "Sunday"; break;
default: cout << "Invalid input!";
}
cout << endl;
return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy