c++.23pdf
c++.23pdf
int main() {
int num;
if (num % 2 == 0)
else
return 0;
1|Page
#include <iostream>
int main() {
int a, b, c;
int largest;
largest = a;
largest = b;
else
largest = c;
cout << "The largest number is: " << largest << endl;
return 0;
2|Page
#include <iostream>
int main() {
int num;
if (num < 0) {
cout << "Factorial is not defined for negative numbers." << endl;
} else {
factorial *= i;
cout << "Factorial of " << num << " is " << factorial << endl;
return 0;
3|Page
#include <iostream>
int main() {
original = num;
while (num != 0) {
num /= 10;
if (original == reversed)
else
return 0;
4|Page
#include <iostream>
int fibonacci(int n) {
if (n <= 1)
return n;
int main() {
int terms;
return 0;
5|Page
#include <iostream>
int main() {
int a, b;
return 0;
6|Page
#include <iostream>
int main() {
int num;
cout << "Global variable using scope resolution operator: " << ::num << endl;
return 0;
7|Page
#include <iostream>
int main() {
int a, b;
cout << "The greater number is: " << max << endl;
return 0;
8|Page
#include <iostream>
int main() {
int a, b;
if (a > b)
else if (b > a)
else
return 0;
9|Page
#include <iostream>
int main() {
float average;
sum += num;
return 0;
10 | P a g e
#include <iostream>
int main() {
float average;
while (i <= 4) {
sum += num;
i++;
return 0;
11 | P a g e
#include <iostream>
int main() {
float average;
do {
sum += num;
i++;
return 0;
12 | P a g e
#include <iostream>
#include <string>
int main() {
getline(cin, str1);
getline(cin, str2);
cout << "Length of first string: " << str1.length() << endl;
if (str1.compare(str2) == 0)
else
return 0;
13 | P a g e
#include <iostream>
int main() {
if (c1 != r2) {
return 0;
result[i][j] = 0;
14 | P a g e
result[i][j] += a[i][k] * b[k][j];
return 0;
15 | P a g e
#include <iostream>
int main() {
int a, b, temp;
temp = a;
a = b;
b = temp;
cout << "a = " << a << "\nb = " << b << endl;
return 0;
16 | P a g e
#include <iostream>
int main() {
int a, b;
a = a + b;
b = a - b;
a = a - b;
cout << "a = " << a << "\nb = " << b << endl;
return 0;
17 | P a g e
#include <iostream>
class Book {
string title;
string author;
float price;
public:
void input() {
getline(cin, title);
getline(cin, author);
void display() {
};
int main() {
Book b;
b.input();
b.display();
18 | P a g e
return 0;
19 | P a g e
#include <iostream>
class Box {
int length;
public:
Box() : length(0) {}
void setLength(int l) {
length = l;
};
void printLength(Box b) {
int main() {
Box b;
b.setLength(15);
printLength(b);
return 0;
#include <iostream>
20 | P a g e
using namespace std;
class Math {
public:
return x * x;
};
int main() {
Math m;
int num;
cout << "Square of " << num << " is: " << m.square(num) << endl;
return 0;
21 | P a g e
#include <iostream>
class Student {
string name;
int age;
public:
Student(string n, int a) {
name = n;
age = a;
~Student() {
void display() {
cout << "Name: " << name << ", Age: " << age << endl;
};
int main() {
s.display();
return 0;
22 | P a g e
#include <iostream>
class Counter {
public:
Counter() {
count++;
cout << "Total objects created: " << count << endl;
};
int Counter::count = 0;
int main() {
Counter::showCount();
return 0;
23 | P a g e
#include <iostream>
int main() {
int rows = 4;
return 0;
24 | P a g e
#include <iostream>
int main() {
int rows = 4;
if (j == 1) {
} else {
if (i == rows && j == i) {
} else {
return 0;
25 | P a g e
#include <iostream>
int main() {
int rows = 5;
if (j == 3) {
if (j == 5) {
cout << j; }
if (j == 2) {
cout << j;
return 0;
26 | P a g e
#include <iostream>
class Number {
int value;
public:
Number(int v = 0) {
value = v;
Number temp;
return temp;
void display() {
};
int main() {
Number c = a + b;
c.display();
return 0;
27 | P a g e
#include <iostream>
class Print {
public:
void show(int i) {
void show(double d) {
};
int main() {
Print obj;
obj.show(5);
obj.show(3.14);
obj.show("Function Overloading");
return 0;
28 | P a g e
#include <iostream>
class Animal {
public:
void sound() {
};
public:
void sound() {
};
int main() {
Dog d;
d.sound();
return 0;
29 | P a g e