MCCP Record
MCCP Record
This is to certify Mr. Manoj Sai Kumar Pasupuleti bearing Rollno. 21A81A4341 of
1|Page
INDEX
Problem Pageno
.
1 Odd or Even no. 06
2 Multiplication Table 07
3 GCD of 2 numbers 08
4 Palindromesx or not 09
Problem Pageno.
1 Prime or not 11
4 Prime String 14
Problem Pageno.
2 Modified Fibonacci 17
4 Composite Series 19
5 Tricky Series 20
2|Page
Problems on Arrays :
Problem Pageno
.
1 Sum of Array 21
3 Perfect Arrays 23
6 Palindromic Array 26
Problems on Strings :
Problem Pageno
.
1 String Concatination 29
2 String Length 30
3 String Reversal 31
4 String Comparision 32
5 String Search 33
6 Sub-String Search 34
8 String Replacement 36
3|Page
Problems on Hashmap & Hashset :
Problem Pageno
.
5 String is isomorphic 41
7 Duplicates in an Array 43
4|Page
Geeks For Geeks Profile
LeetCode Profile
5|Page
PROBLEMS ON MATH LOGIC
Testcase 1:
Input: Enter an Integer: 2
Output: 2 is even
Testcase 2:
Input: Enter an Integer: 1
Output: 1 is odd
Testcase 3:
Input: Enter an Integer: 0
Output: 0 is even
Program :
#include <iostream>
int main() {
int number;
if (number % 2 == 0) {
std::cout << number << " is even." << std::endl;
} else {
std::cout << number << " is odd." << std::endl;
}
return 0;
}
6|Page
PROBLEMS ON MATH LOGIC
Testcase :
Input: N = 9
Output: 9 18 27 36 45 54 63 72 81 90
Program :
#include <iostream>
#include <vector>
std::vector<int> generateMultiplicationTable(int N) {
std::vector<int> table;
return table;
}
int main() {
int N;
std::cout <<std::endl;
for (int i = 0; i < multiplicationTable.size(); i++) {
std::cout << multiplicationTable[i];
if (i < 9) {
std::cout << " ";
}
}
std::cout << std::endl;
return 0;
}
7|Page
PROBLEMS ON MATH LOGIC
Testcase 1 :
Input: A = 3, B = 6
Output: 3
Testcase 2 :
Input: A = 1, B = 1
Output: 1
Program :
#include <iostream>
#include <algorithm>
int main() {
int A, B;
return 0;
}
8|Page
PROBLEMS ON MATH LOGIC
04. Given a number N.Find if the digit sum (or sum of digits)
of N is a Palindrome number or not.
Testcase :
Input: N = 56
Output: 1
Program :
#include <iostream>
int reverseNumber(int num) {
int reversedNum = 0;
while (num > 0) {
int digit = num % 10;
reversedNum = reversedNum * 10 + digit;
num /= 10;
}
return reversedNum;
}
bool isPalindrome(int num) {
int reversedNum = reverseNumber(num);
return num == reversedNum;
}
int main() {
int N;
std::cout << "N = ";
std::cin >> N;
int digitSum = 0;
int originalNumber = N;
while (N > 0) {
digitSum += N % 10;
N /= 10;
}
if (isPalindrome(digitSum)) {
std::cout << "1\n";
} else {
std::cout << "0\n";
}
9|Page
return 0;
}
Testcase 2 :
Input: Enter the value of N: 3
Output: The 3th term in the series is: 6
Program :
#include <iostream>
int findNthTerm(int N) {
return N * (N + 1) / 2;
}
int main() {
int N;
std::cout << "Enter the value of N: ";
std::cin >> N;
std::cout << "The " << N << "th term in the series is: " << result <<
std::endl;
return 0;
}
10 | P a g e
PROBLEMS ON PRIME NUMBERS
Testcase 2:
Input: Enter an number: 3
Output: 3 is a prime number
Program :
#include <iostream>
#include <cmath>
bool isPrime(int N) {
if (N <= 1) {
return false;
}
if (N <= 3) {
return true;
}
if (N % 2 == 0 || N % 3 == 0) {
return false;
}
Testcase 2:
Input: Enter an number: 31
Output: 31 is not a Full Prime number.
Program :
#include <iostream>
bool isPrime(int num) {
if (num <= 1) return false;
if (num <= 3) return true;
if (num % 2 == 0 || num % 3 == 0) return false;
12 | P a g e
std::cout << N << " is a Full Prime number." << std::endl;
} else {
std::cout << N << " is not a Full Prime number." << std::endl;
}
return 0;
}
if (isPrimeString(input)) {
std::cout << "The string is a prime string." << std::endl;
14 | P a g e
} else {
std::cout << "The string is not a prime string." << std::endl;
}
return 0;
}
#include <iostream>
#include <cmath>
bool isPrime(int num) {
if (num <= 1) return false;
if (num <= 3) return true;
if (num % 2 == 0 || num % 3 == 0) return false;
if (isPrime(singleDigitSum)) {
std::cout << singleDigitSum << " is a prime number." << std::endl;
15 | P a g e
} else {
std::cout << singleDigitSum << " is not a prime number." << std::endl;
}
return 0;
}
Testcase 2 :
Input: Enter the value of n: 13
Output: The 3th Fibonacci number is: 233
Program :
#include <iostream>
int fibonacci(int n) {
if (n <= 1)
return n;
int prev = 0;
int current = 1;
int next;
for (int i = 2; i <= n; i++) {
next = prev + current;
prev = current;
current = next;
}
return current;
}
int main() {
int n;
std::cout << "Enter the value of n: ";
std::cin >> n;
if (n < 0) {
std::cout << "Invalid input. Please enter a non-negative integer." <<
std::endl;
} else {
16 | P a g e
int result = fibonacci(n);
std::cout << "The " << n << "th Fibonacci number is: " << result <<
std::endl;
}
return 0;
}
Program :
#include <iostream>
int calculateF(int A, int B, int C, int N) {
if (N < 1) return -1;
if (N == 1) return A + B;
if (N == 2) return B + C;
int FnMinus1 = B + C;
int FnMinus2 = A + B;
int Fn;
for (int i = 3; i <= N; i++) {
Fn = FnMinus1 - FnMinus2;
FnMinus2 = FnMinus1;
FnMinus1 = Fn;
}
return Fn;
}
int main() {
int A, B, C, N;
std::cout << "Enter A, B, C, and N: ";
std::cin >> A >> B >> C >> N;
int result = calculateF(A, B, C, N);
if (result != -1) {
17 | P a g e
std::cout << "F(" << N << ") = " << result << std::endl;
} else {
std::cout << "Invalid input. N must be a positive integer." << std::endl;
}
return 0;
}
Program :
#include <iostream>
const int MOD = 1000000007;
int findNthEvenFibonacci(int N) {
if (N <= 0) return 0;
long long a = 0;
long long b = 1;
int evenFib = 0;
int count = 0;
while (count < N) {
long long next = a + b;
if (next % 2 == 0) {
evenFib = next % MOD;
count++;
}
a = b;
b = next % MOD;
}
return evenFib;
}
int main() {
int N;
std::cout << "Enter a positive integer N: ";
18 | P a g e
std::cin >> N;
int result = findNthEvenFibonacci(N);
std::cout << "The " << N << "th even Fibonacci number modulo 1000000007 is: "
<< result << std::endl;
return 0;
}
04. Given a number N, print all the composite numbers less than or equal to N.
The number should be printed in ascending order.
Testcase :
Input: Enter a integer N: 10
Output: 4 6 8 9 10
Program :
#include <iostream>
Program :
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter the value of n: ";
cin >> n;
cout << "The " << n << "th term of the series is: " << nthTerm(n) << endl;
return 0;
}
20 | P a g e
PROBLEMS ON ARRAY
Program :
#include <iostream>
int main() {
int n;
std::cout << "Enter the number of elements in the array: ";
std::cin >> n;
if (n <= 0) {
std::cout << "Invalid array size. Please enter a positive integer." <<
std::endl;
return 1;
}
int sum = 0;
for (int i = 0; i < n; i++) {
21 | P a g e
sum += arr[i];
}
std::cout << "Sum of elements in the array: " << sum << std::endl;
delete[] arr;
return 0;
}
PROBLEMS ON ARRAY
PROBLEMS ON ARRAY
#include <iostream>
#include <vector>
#include <cmath>
bool isPerfectArray(const std::vector<int>& arr) {
if (arr.size() <= 1) {
return true;
}
int commonDifference = std::abs(arr[1] - arr[0]);
for (size_t i = 1; i < arr.size() - 1; i++) {
int diff = std::abs(arr[i + 1] - arr[i]);
if (diff != commonDifference) {
return false;}
} return true;
}
int main() {
std::vector<int> arr;
int n;
std::cout << "Enter the number of elements in the array: ";
std::cin >> n;
if (n <= 0) {
std::cout << "Invalid array size. Please enter a positive integer." <<
std::endl;
23 | P a g e
return 1;}
std::cout << "Enter " << n << " elements: ";
for (int i = 0; i < n; i++) {
int element;
std::cin >> element;
arr.push_back(element);
}
if (isPerfectArray(arr)) {
std::cout << "The given array is a perfect array." << std::endl;
} else {
std::cout << "The given array is not a perfect array." << std::endl;
}
return 0;
}
PROBLEMS ON ARRAY
Program :
#include <iostream>
#include <vector>
void swapKthElement(std::vector<int>& arr, int k, int newValue) {
if (k >= 0 && k < arr.size()) {
arr[k] = newValue; }
}
int main() {
int n;
std::cout << "Enter the number of elements in the array: ";
std::cin >> n;
std::vector<int> arr(n);
std::cout << "Enter " << n << " elements: ";
for (int i = 0; i < n; i++) {
std::cin >> arr[i];
}
int k, newValue;
std::cout << "Enter the index (k) to swap (0-based): ";
std::cin >> k;
24 | P a g e
if (k < 0 || k >= n) {
std::cout << "Invalid index. Please enter a valid index." << std::endl;
return 1;
}
std::cout << "Enter the new value: ";
std::cin >> newValue;
swapKthElement(arr, k, newValue);
std::cout << "Array after swapping the " << k << "-th element with " <<
newValue << ": ";
for (int value : arr) {
std::cout << value << " ";
}
return 0;
}
PROBLEMS ON ARRAY
Program :
#include <iostream>
#include <vector>
#include <string>
std::string findLongestString(const std::vector<std::string>& arr) {
if (arr.empty()) {
return "";
}
std::string longest = arr[0];
for (const std::string& str : arr) {
if (str.length() > longest.length()) {
longest = str;
}
}
return longest;
}
int main() {
int n;
std::cout << "Enter the number of strings in the array: ";
std::cin >> n;
25 | P a g e
std::vector<std::string> arr(n);
std::cout << "Enter " << n << " strings: ";
for (int i = 0; i < n; i++) {
std::cin >> arr[i];
}
std::string longestString = findLongestString(arr);
if (longestString.empty()) {
std::cout << "The array is empty." << std::endl;
} else {
std::cout << longestString << std::endl;
}
return 0;
}
PROBLEMS ON ARRAY
Program :
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter the size of the array: ";
cin >> n;
int arr[n];
cout << "Enter the elements of the array: ";
for (int i = 0; i < n; ++i) {
26 | P a g e
cin >> arr[i];
}
if (isPalindromicArray(arr, n)) {
cout << "The array is palindromic." << endl;
} else {
cout << "The array is not palindromic." << endl;
}
return 0;
}
PROBLEMS ON ARRAY
Program :
#include <iostream>
using namespace std;
int sum = 0;
for (int i = 0; i < n; ++i) {
sum += arr[i];
}
return static_cast<double>(sum) / n;
}
int main() {
int n;
cout << "Enter the size of the array: ";
27 | P a g e
cin >> n;
int arr[n];
cout << "Enter the elements of the array: ";
for (int i = 0; i < n; ++i) {
cin >> arr[i];
}
cout << "The average is: " << average << endl;
return 0;
}
PROBLEMS ON ARRAY
Program :
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter the size of the array: ";
cin >> n;
int arr[n];
cout << "Enter the elements of the array: ";
for (int i = 0; i < n; ++i) {
28 | P a g e
cin >> arr[i];
}
printAlternateElements(arr, n);
return 0;
}
PROBLEMS ON STRINGS
Program :
#include <iostream>
#include <string>
using namespace std;
int main() {
cout << "Enter the first string: ";
string firstString;
getline(cin, firstString);
29 | P a g e
cout << "Concatenated String: " << concatenatedString << endl;
return 0;
}
PROBLEMS ON STRINGS
#include <iostream>
#include <string>
using namespace std;
int main() {
cout << "Enter a string: ";
string userInput;
getline(cin, userInput);
cout << "Length of the string: " << userInput.length() << endl;
return 0;
}
30 | P a g e
PROBLEMS ON STRINGS
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
cout << "Enter a string: ";
string userInput;
getline(cin, userInput);
return 0;
}
31 | P a g e
PROBLEMS ON STRINGS
#include <iostream>
#include <string>
using namespace std;
int main() {
cout << "Enter the first string: ";
string firstString;
getline(cin, firstString);
if (firstString == secondString) {
cout << "Strings are equal." << endl;
} else {
cout << "Strings are not equal." << endl;
}
32 | P a g e
return 0;
}
PROBLEMS ON STRINGS
#include <iostream>
#include <string>
using namespace std;
int main() {
cout << "Enter a sentence: ";
string sentence;
getline(cin, sentence);
if (sentence.find(searchWord) != string::npos) {
cout << "Word found in the sentence." << endl;
} else {
cout << "Word not found in the sentence." << endl;
33 | P a g e
}
return 0;
}
PROBLEMS ON STRINGS
#include <iostream>
#include <string>
using namespace std;
int main() {
cout << "Enter a sentence: ";
string sentence;
getline(cin, sentence);
if (sentence.find(substring) != string::npos) {
cout << "Substring found in the sentence." << endl;
} else {
34 | P a g e
cout << "Substring not found in the sentence." << endl;
}
return 0;
}
PROBLEMS ON STRINGS
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
cout << "Enter a string: ";
string userInput;
getline(cin, userInput);
// Convert to uppercase
transform(userInput.begin(), userInput.end(), userInput.begin(), ::toupper);
cout << "Uppercase: " << userInput << endl;
// Convert to lowercase
transform(userInput.begin(), userInput.end(), userInput.begin(), ::tolower);
35 | P a g e
cout << "Lowercase: " << userInput << endl;
return 0;
}
PROBLEMS ON STRINGS
int main() {
cout << "Enter a sentence: ";
string sentence;
getline(cin, sentence);
return 0;
}
Program:
#include <iostream>
#include <unordered_map>
using namespace std;
int main() {
unordered_map<string, int> myMap;
string key;
int value;
myMap[key] = value;
cout << "Value for key " << key << ": " << myMap[key] << endl;
return 0;
}
Program:
#include <iostream>
#include <unordered_set>
using namespace std;
int main() {
unordered_set<int> mySet;
int element;
cout << "Enter an element to insert into the set: ";
cin >> element;
mySet.insert(element);
return 0;
38 | P a g e
}
Program:
#include <iostream>
#include <unordered_set>
#include <vector>
using namespace std;
int main() {
int size;
cout << "Enter the size of the vector: ";
cin >> size;
39 | P a g e
vector<int> numbers(size);
cout << "Distinct elements count: " << countDistinct(numbers) << endl;
return 0;
}
40 | P a g e
}
cout << "Frequency of elements:\n";
for (const auto& pair : freqMap) {
cout << pair.first << ": " << pair.second << " times\n";
}
}
int main() {
int size;
cout << "Enter the size of the vector: ";
cin >> size;
vector<int> numbers(size);
cout << "Enter elements of the vector: ";
for (int i = 0; i < size; ++i) {
cin >> numbers[i];
}
countFrequency(numbers);
return 0;
}
int main() {
int size;
cout << "Enter the size of the vector: ";
cin >> size;
vector<int> numbers(size);
countFrequency(numbers);
return 0;
}
return 0;
}
int main() {
int n;
cout << "Enter the size of the array: ";
cin >> n;
vector<int> nums(n);
cout << "Enter elements of the array: ";
for (int i = 0; i < n; ++i) {
cin >> nums[i];
43 | P a g e
}
unordered_set<int> numSet;
if (hasDuplicates) {
cout << "The array contains duplicates.\n";
} else {
cout << "The array does not contain duplicates.\n";
}
return 0;
}
44 | P a g e
cout << "Enter the size of the second array: ";
cin >> size2;
vector<int> nums2(size2);
cout << "Enter elements of the second array: ";
for (int i = 0; i < size2; ++i) {
cin >> nums2[i];
}
unordered_set<int> set1(nums1.begin(), nums1.end());
unordered_set<int> commonElements;
for (int num : nums2) {
if (set1.count(num) > 0) {
commonElements.insert(num);
}
}
cout << "Common elements: ";
for (int num : commonElements) {
cout << num << " ";
}
cout << endl;
return 0;
}
45 | P a g e
cout << "Frequency of elements:\n";
for (const auto& pair : freqMap) {
cout << pair.first << ": " << pair.second << " times\n";
}
}
int main() {
int size;
cout << "Enter the size of the vector: ";
cin >> size;
vector<int> numbers(size);
countFrequency(numbers);
return 0;
}
46 | P a g e