21. Write a program to remove duplicate characters from a string.

Required Input:

std::string str = "programming";

Expected Output:

String after removing duplicates: progamin

Code In Cpp

#include #include #include int main() { std::string str = "programming"; // Logic to remove duplicates return 0; }

Output

Click Run Button to view compiled output

22. Implement a program to find the longest word in a sentence.

Required Input:

std::string sentence = "Find the longest word in this sentence";

Expected Output:

Longest word = sentence

Code In Cpp

#include #include #include int main() { std::string sentence = "Find the longest word in this sentence"; // Logic to find the longest word return 0; }

Output

Click Run Button to view compiled output

23. Write a program to check if a number is Armstrong or not.

Required Input:

int n = 153;

Expected Output:

153 is an Armstrong number.

Code In Cpp

#include #include int main() { int n = 153; // Logic to check Armstrong number return 0; }

Output

Click Run Button to view compiled output

24. Implement a program to convert a binary number to decimal.

Required Input:

int binary = 1011;

Expected Output:

Decimal = 11

Code In Cpp

#include int main() { int binary = 1011; // Logic to convert binary to decimal return 0; }

Output

Click Run Button to view compiled output

25. Write a program to check if a number is a perfect number.

Required Input:

int n = 28;

Expected Output:

28 is a perfect number.

Code In Cpp

#include int main() { int n = 28; // Logic to check perfect number return 0; }

Output

Click Run Button to view compiled output

26. Write a program to implement a bubble sort algorithm on an array.

Required Input:

int arr[] = {64, 34, 25, 12, 22, 11, 90};

Expected Output:

Sorted array: 11 12 22 25 34 64 90 

Code In Cpp

#include int main() { int arr[] = {64, 34, 25, 12, 22, 11, 90}; // Logic to implement bubble sort return 0; }

Output

Click Run Button to view compiled output

27. Write a program to calculate the sum of elements in an array.

Required Input:

int arr[] = {1, 2, 3, 4, 5};

Expected Output:

Sum of elements: 15

Code In Cpp

#include int main() { int arr[] = {1, 2, 3, 4, 5}; // Logic to calculate the sum of elements return 0; }

Output

Click Run Button to view compiled output

28. Implement a program to perform a linear search on an array.

Required Input:

int arr[] = {2, 4, 6, 8, 10}; and int key = 6;

Expected Output:

Element found at index: 2

Code In Cpp

#include int main() { int arr[] = {2, 4, 6, 8, 10}; int key = 6; // Logic to perform linear search return 0; }

Output

Click Run Button to view compiled output

29. Write a program to implement a basic stack using an array.

Required Input:

Push elements 10, 20, 30, then pop an element.

Expected Output:

Popped element: 30

Code In Cpp

#include #define MAX 100 class Stack { private: int arr[MAX]; int top; public: Stack(); void push(int x); int pop(); bool isEmpty(); }; int main() { // Logic to demonstrate stack operations return 0; }

Output

Click Run Button to view compiled output

30. Create a program that uses exception handling to handle division by zero errors.

Required Input:

int a = 10; int b = 0;

Expected Output:

Result: Division by zero error.

Code In Cpp

#include #include int divide(int a, int b); int main() { int a = 10, b = 0; // Logic to perform division and handle exceptions return 0; }

Output

Click Run Button to view compiled output

ad vertical

3 of 3