Assignments
C++ Assignments 1
Assignments Solution
Q1. How can you output “Physics” and “Wallah” in two different lines in C++?
Solution:
#include <iostream>
using namespace std;
int main() {
cout << "Physics" << endl;
cout << "Wallah" << endl;
return 0;
Q2. Print 10 using 2 positive numbers less than 6 in C++ as output.
Solution:
#include <iostream>
using namespace std;
int main() {
cout << 5 + 5 << endl;
Q3. How much space does the following data types take?
int
bool
float
Solution:
int 4 bytes
bool 1 byte
float 4 bytes
Q4. What is the output of this program?
int main() {
int a = 4;
int b = 5;
a++, b--;
cout << ++a << " " << b--;
Solution:
6 4
Java + DSA
Assignments Solution
Q5. WAP to find the circumference of a circle with radius 10 in C++.
Solution:
#include <iostream>
using namespace std;
int main() {
int r = 10;
float pi = 3.14;
float circumference = 2 * pi * r;
cout << circumference;
return 0;
Q6. How many of these can be a variable name ?
01Pwskills
_FLOAT
int
FLOAT
You will succeed
Solution:
Only 2 of the above can be a variable name.
1st option is incorrect since a variable name cannot start with a number.
2nd option is correct because a variable name can start with underscore.
3rd option is incorrect as a variable name because int is a reserved keyword and cannot be used as a
variable name.
4th option is still correct because C++ is a case sensitive language. Here FLOAT and float are treated
differently therefore FLOAT is not a reserved keyword hence can be used as variable name.
Last option is incorrect because no variable can have spaces in between.
Copyright © 2023 Physics Wallah Pvt. Ltd. All rights reserved.
Java + DSA
THANK
YOU !