Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
28 views47 pages

C++ Functions for Number and String Operations

Uploaded by

m.alshehari2
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)
28 views47 pages

C++ Functions for Number and String Operations

Uploaded by

m.alshehari2
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

#include <iostream>

#include <math.h>

#include <vector>

#include <map>

#include <sstream>

#include <string>

using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

// ‫ايجاد العدد التام‬

bool per(int a){

int sum=0;

for(int i=1; i<=a/2;i++){

if(a%i==0){

sum+=i;

if(a==sum&&a!=0)

return true;

else

return false;

// ‫ايجاد العدد المتناظر‬

bool isPalindrome(int num) {

if (num < 0) {

return false;

int reversedNum = 0;

int originalNum = num;


while (originalNum > 0) {

int digit = originalNum % 10;

reversedNum = reversedNum * 10 + digit;

originalNum /= 10;

return num == reversedNum;

//‫ايجاد الحروف المتحركة‬

int countvowels(string str){

int vowelscount=0;

string vowels="AEIOUaeiou";

for(char& c:str){

if([Link](c)!=string::npos){

vowelscount++;

return vowelscount;

//‫ايجاد عدد الكلمات في سلسلة حرفية‬

int countwords(string input)

stringstream s(input);

string word;

int count=0;

while(s>>word)

count++;
}

return count;

bool searchelement(int arr[],int size,int key){

for(int i=0;i<size-1;i++){

if(arr[i]==key){

return true;

return false;

//‫طباعة العناصر غيرر المتكررة‬

void print_unique_elements(const std::vector<int>& array) {

map <int, int> counts;

for (int element : array) {

counts[element]++;

cout << "The unique elements in the array are: ";

for (const auto& pair : counts) {

if ([Link] == 1) {

cout << [Link] << " ";

cout << std::endl;

}
// ‫ايجاد طول السلسلة الحرفية‬

int strlength(std::string text) {

int length = 0;

while (text[length] != '\0') {

length++;

return length;

// ‫نسخ سلسلة الى سلسلة اخرى‬

void copyString(char s1[], char s2[]) {

int i = 0;

while (s1[i] != '\0') {

s2[i] = s1[i];

i++;

s2[i] = '\0';

// ‫مجموع عناصر المصفوفة‬

int sumArray(int arr[], int size) {

int sum = 0;

for (int i = 0; i < size; i++) {

sum += arr[i];

return sum;

}
// ‫البحث عن عنصر في مصفوفة‬

bool searchElement(int arr[], int size, int toSearch) {

for (int i = 0; i < size; i++) {

if (arr[i] == toSearch) {

return true;

return false;

int main(int argc, char** argv) {

int select;

cout<<"press 1 to found the prime numbers"<<endl;

cout<<"press 2 to change to 0,1"<<endl;

cout<<"press 3 to check the number(even or odd)"<<endl;

cout<<"press 4 to apear the series1+11+111+1111+....n with sum"<<endl;

cout<<"press 5 to check the perfect number"<<endl;

cout<<"press 6 to check the plindrome number"<<endl;

cout<<"press 7 to found the second largest element"<<endl;

cout<<"press 8 to order the array and print it"<<endl;

cout<<"press 9 to count even number or odd"<<endl;

cout<<"press 10 to sum every row and print it"<<endl;

cout<<"press 11 to sum every column and print it "<<endl;

cout<<"press 12 to change the secondary row to negative values"<<endl;

cout<<"press 13 to change the array from 1*4 to 2*2"<<endl;

cout<<"press 14 to sum the border elements "<<endl;

cout<<"press 15 to sum arr1+arr2 to arr2v "<<endl;

cout<<"press 16 to count the vowel letters "<<endl;


cout<<"press 17 to now count of words "<<endl;

cout<<"press 18 to change the capital letter to small letter "<<endl;

cout<<"press 19 to change the small letter to capital letter "<<endl;

cout<<"press 20 to print unique elements "<<endl;

cout<<"press 21 to find size of series "<<endl;

cout<<"press 22 to copy series to another series "<<endl;

cout<<"press 23 to sum the elements of array "<<endl;

cout<<"press 24 to sum component the entered element "<<endl;

cout<<"press 25 to search for element in the array "<<endl;

cin>>select;

switch(select){

case 1:{

int start,end;

bool prime=true;

cout<<"enter the first number"<<endl;

cin>>start;

cout<<"enter the end number"<<endl;

cin>>end;

cout<<"the prime numbers between"<<start<<"and"<<end<<"are:"<<endl;

for(int i=start; i<=end;i++){

for(int j=2; j<=sqrt(i);j++){

if(i%j==0)

prime=false;

if(prime==true&& i!=1)

cout<<i<<" ";
}

prime=true;

break;

case 2:{

int n,r;

cout<<"enter the decimal number\n";

cin>>n;

while(n/2>0){

r=n%2;

cout<<r<<" ";

n=n/2;

cout<<1;

break;

case 3:{

char ch;

int a;

do{
cout<<"enter the number to check"<<endl;

cin>>a;

cout<<endl;

if(a%2==0)

cout<<"is even"<<endl;

else

cout<<"is odd"<<endl;

cout<<"do you want to again:y\n"<<endl;

cin>> ch;

while(ch=='y');

break;

case 4:{

int num,s=0,sum=0;

cout<<"enter the number of term"<<endl;

cin>>num;

for(int i=1;i<=num;i++){

s=s*10+1;

cout<<s<<" ";

sum=sum+s;

cout<<"\nthe sum of series="<<sum;

break;

case 5:{
int a;

cout<<"enter the number for checking\n";

cin>>a;

if(per(a)){

cout<<"number"<<a<<"is perfect number"<<endl;

else{

cout<<"number"<<a<<"not perfect number"<<endl;

break;

case 6:{

int num;

cout << "Enter a number: ";

cin >> num;

if (isPalindrome(num)) {

cout << num << " is a palindrome." << endl;

} else {

cout << num << " is not a palindrome." << endl;

break;

case 7:{

int arr [100];

int n ;// Size of the array


cout<<"enter the size of array:\n";

cin>>n;

cout<<"enter the elements of array:\n";

for (int i=0; i<n; i++){

cin>>arr[i];

int largest = arr[0];

for (int i = 1; i < n; i++) {

if (arr[i] > largest) {

largest = arr[i];

int second_largest = INT_MIN;

for (int i = 0; i < n; i++) {

if (arr[i] != largest && arr[i] > second_largest) {

second_largest = arr[i];

if (second_largest != INT_MIN) {

cout << "The second largest element in the array is: " << second_largest << endl;

} else {

cout << "Error: Array has only one distinct element or an error occurred." << endl;

}
break;

case 8:{

int n;

cout << "enter the size of array: ";

cin >> n;

int arr[n];

for (int i = 0; i < n; i++) {

cout << "enter the elements of array " << i + 1 << ": ";

cin >> arr[i];

for (int i = 0; i < n; i++) {

for (int j = 0; j < n - i - 1; j++) {

if (arr[j] > arr[j + 1]) {

int temp = arr[j];

arr[j] = arr[j + 1];

arr[j + 1] = temp;

cout << "the array after order it: ";

for (int i = 0; i < n; i++) {


cout << arr[i] << " ";

break;

case 9:{

int numbers[10];

int evencount=0;

int oddcount=0;

cout<<"enter the number to check\n";

for(int i=0; i<10; i++){

cin>>numbers[i];

for(int i=0;i<sizeof(numbers)/sizeof(numbers[10]);i++){

if(numbers[i]%2==0)

evencount++;

else

oddcount++;

cout<<"the even numbers are:\n"<<evencount<<endl;

cout<<"the odd numbers are:\n"<<oddcount<<endl;

break;

case 10:{

const int classa=3;

const int columns=3;

int aray[classa][columns];

cout<<"enter"<<classa* columns<<"value of aray of 3*3:"<<endl;

for(int i=0; i<classa; i++){


for(int j=0; j<columns; j++) {

cin>>aray[i][j];

for(int i=0; i<classa; ++i){

int total=0;

for(int j=0; j<columns; j++){

total+=aray[i][j];

cout<<"total items in the row"<<i+1<<"is:"<<total<<endl;

break;

case 11:{

int matrix[3][3];

for (int i = 0; i < 3; i++) {

for (int j = 0; j < 3; j++) {

cout << "Enter the value of element (" << i + 1 << "," << j + 1 << "): ";

cin >> matrix[i][j];

int columnSums[3] = {0};

for (int i = 0; i < 3; i++) {


for (int j = 0; j < 3; j++) {

columnSums[j] += matrix[i][j];

cout << "\nThe matrix:\n";

for (int i = 0; i < 3; i++) {

for (int j = 0; j < 3; j++) {

cout << matrix[i][j] << " ";

cout << endl;

cout << "\nThe column sums:\n";

for (int i = 0; i < 3; i++) {

cout << "Sum of column " << i + 1 << ": " << columnSums[i] << endl;

break;

case 12:{

const int rows=3;

const int cols=3;

int matrix[rows][cols];

cout<<"enter the value for3*3 matrix:\n";

for(int i=0;i<rows;++i){

for(int j=0;j<cols;++j){

cin>>matrix[i][j];

}
for(int i=0;i<rows;++i){

for(int j=0;j<cols;++j){

if(i+j==cols-1){

matrix[i][j]=-matrix[i][j];

cout<<"\n matrix after change secondary daigonal elements to negative values\n";

for(int i=0;i<rows;++i){

for(int j=0;j<cols;++j){

cout<<matrix[i][j]<<" ";

cout<<endl;

break;

case 13:{

int arr[4];

int array[2][2];

cout<<"enter the value for elements\n";

for(int i=0;i<4;i++)

cin>>arr[i];
int index=0;

for(int i=0;i<2;i++){

for(int j=0;j<2;j++){

array[i][j]=arr[index];

index++;

cout<<"the result is:\n";

for(int i=0;i<2;i++){

for(int j=0;j<2;j++){

cout<< array[i][j]<<"\t";

cout<<"\n";

break;

case 14:

int arr[3][3];

int sum=0;

cout<<"enter the numbers of array3*3\n";

for(int i=0;i<3;i++){

for(int j=0;j<3;j++){

cin>>arr[i][j];

for(int i=0;i<3;i++){

for(int j=0;j<3;j++){

if(i==0||i==2||j==0||j==2)
{

sum+=arr[i][j];

cout<<"the sum for frontier numbers is:"<<sum<<endl;

break;

case 15:{

int arr1[3][3];

int arr2[3][3];

cout<<"enter the values for array 1:"<<" ";

for(int i=0;i<3;i++){

for(int j=0;j<3;j++){

cin>>arr1[i][j];

cout<<"enter the values for array 2:"<<" ";

for(int i=0;i<3;i++){

for(int j=0;j<3;j++){

cin>>arr2[i][j];

arr2[i][j]+=arr1[i][j];

}
cout<<"the sum of two arrays is:"<<endl;

for(int i=0;i<3;i++){

for(int j=0;j<3;j++){

cout<<arr2[i][j]<<" ";

cout<<endl;

break;

case 16:{

string inputstring;

cout<<"enter the series of letters:";

getline(cin,inputstring);

int vowelscount=countvowels(inputstring);

cout<<"the count of vowel letters is:"<<vowelscount<<endl;

break;

case 17:{

string inputstring;

cout<<"enter the words:"<<endl;

getline(cin,inputstring);

int word = countwords(inputstring);

cout<<"the count of word is:" <<word<<endl;


}

break;

case 18:{

char str[100];

cout<<" enter the capital characters\n";

[Link](str,100) ;

for(int i=0;i<(str,100);i++){

if(str[i]>='A'&& str[i]<='Z')

str[i]+=32;

cout<<"the small letters is:"<<str<<endl;

break;

case 19:{

char str[100];

cout<<"enter the small characters:\n";

[Link](str,100);

for(int i=0; i<(str,100);i++)

if(str[i]>='a'&& str[i]<='z')

str[i]-=32;

cout<<"the capital letter is:"<<str<<endl;

break;

case 20:{

int size;

cout << "Enter the size of the array: ";


cin >> size;

vector<int> array(size);

for (int i = 0; i < size; i++) {

cout << "Enter element " << i + 1 << ": ";

cin >> array[i];

print_unique_elements(array);

break;

case 21:{

string str;

cout << "Enter a string: ";

getline(cin, str);

cout << "The length of the string is: " << strlength(str) << std::endl;

break;

case 22:{

char original[] = "Hello, World!";

char copy[20];

copyString(original, copy);

cout << "Original string: " << original << endl;

cout << "Copied string: " << copy << endl;


}

break;

case 23:{

int size;

cout << "Enter the number of elements in the array: ";

cin >> size;

if (size <= 0) {

cout << "Invalid input. Array size must be a positive integer." << endl;

return 1;

int arr[size];

cout << "Enter the array elements: " << endl;

for (int i = 0; i < size; i++) {

cout << "Element " << i + 1 << ": ";

cin >> arr[i];

int total = sumArray(arr, size);

cout << "The sum of the array elements is: " << total << endl;

break;

case 24:{
int size;

cout << "Enter the number of elements in the array: ";

cin >> size;

if (size <= 0) {

cout << "Invalid input. Array size must be a positive integer." << endl;

return 1;

int arr[size];

cout << "Enter the array elements: " << endl;

for (int i = 0; i < size; i++) {

cout << "Element " << i + 1 << ": ";

cin >> arr[i];

int numToSearch;

cout << "Enter the element to search for: ";

cin >> numToSearch;

bool found = searchElement(arr, size, numToSearch);

if (found) {
cout << "The element " << numToSearch << " was found in the array." << endl;

} else {

cout << "The element " << numToSearch << " was not found in the array." << endl;

break;

case 25:{

int size, key;

cout<<"enter thr size of array:";

cin>>size;

int arr[size];

cout<<"enter"<<size<<"elements of array:";

for(int i=0;i<size;i++){

cin>>arr[i];

cout<<"enter the element to search for:";

cin>>key;

if(searchelement(arr,size,key)){

cout<<"element found in the array."<<endl;

else{

cout<<"element not found in the array."<<endl;

break;

default:
cout<<"error";

return 0;

#include <iostream>

#include <math.h>

#include <vector>

#include <map>

#include <sstream>

#include <string>

using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

// ‫ايجاد العدد التام‬

bool per(int a){

int sum=0;

for(int i=1; i<=a/2;i++){

if(a%i==0){

sum+=i;

if(a==sum&&a!=0)

return true;

else

return false;

}
// ‫ايجاد العدد المتناظر‬

bool isPalindrome(int num) {

if (num < 0) {

return false;

int reversedNum = 0;

int originalNum = num;

while (originalNum > 0) {

int digit = originalNum % 10;

reversedNum = reversedNum * 10 + digit;

originalNum /= 10;

return num == reversedNum;

//‫ايجاد الحروف المتحركة‬

int countvowels(string str){

int vowelscount=0;

string vowels="AEIOUaeiou";

for(char& c:str){

if([Link](c)!=string::npos){

vowelscount++;

return vowelscount;

//‫ايجاد عدد الكلمات في سلسلة حرفية‬


int countwords(string input)

stringstream s(input);

string word;

int count=0;

while(s>>word)

count++;

return count;

bool searchelement(int arr[],int size,int key){

for(int i=0;i<size-1;i++){

if(arr[i]==key){

return true;

return false;

//‫طباعة العناصر غيرر المتكررة‬

void print_unique_elements(const std::vector<int>& array) {

map <int, int> counts;

for (int element : array) {

counts[element]++;

}
cout << "The unique elements in the array are: ";

for (const auto& pair : counts) {

if ([Link] == 1) {

cout << [Link] << " ";

cout << std::endl;

// ‫ايجاد طول السلسلة الحرفية‬

int strlength(std::string text) {

int length = 0;

while (text[length] != '\0') {

length++;

return length;

// ‫نسخ سلسلة الى سلسلة اخرى‬

void copyString(char s1[], char s2[]) {

int i = 0;

while (s1[i] != '\0') {

s2[i] = s1[i];

i++;

s2[i] = '\0';

}
// ‫مجموع عناصر المصفوفة‬

int sumArray(int arr[], int size) {

int sum = 0;

for (int i = 0; i < size; i++) {

sum += arr[i];

return sum;

// ‫البحث عن عنصر في مصفوفة‬

bool searchElement(int arr[], int size, int toSearch) {

for (int i = 0; i < size; i++) {

if (arr[i] == toSearch) {

return true;

return false;

int main(int argc, char** argv) {

int select;

cout<<"press 1 to found the prime numbers"<<endl;

cout<<"press 2 to change to 0,1"<<endl;

cout<<"press 3 to check the number(even or odd)"<<endl;

cout<<"press 4 to apear the series1+11+111+1111+....n with sum"<<endl;

cout<<"press 5 to check the perfect number"<<endl;

cout<<"press 6 to check the plindrome number"<<endl;

cout<<"press 7 to found the second largest element"<<endl;

cout<<"press 8 to order the array and print it"<<endl;


cout<<"press 9 to count even number or odd"<<endl;

cout<<"press 10 to sum every row and print it"<<endl;

cout<<"press 11 to sum every column and print it "<<endl;

cout<<"press 12 to change the secondary row to negative values"<<endl;

cout<<"press 13 to change the array from 1*4 to 2*2"<<endl;

cout<<"press 14 to sum the border elements "<<endl;

cout<<"press 15 to sum arr1+arr2 to arr2v "<<endl;

cout<<"press 16 to count the vowel letters "<<endl;

cout<<"press 17 to now count of words "<<endl;

cout<<"press 18 to change the capital letter to small letter "<<endl;

cout<<"press 19 to change the small letter to capital letter "<<endl;

cout<<"press 20 to print unique elements "<<endl;

cout<<"press 21 to find size of series "<<endl;

cout<<"press 22 to copy series to another series "<<endl;

cout<<"press 23 to sum the elements of array "<<endl;

cout<<"press 24 to sum component the entered element "<<endl;

cout<<"press 25 to search for element in the array "<<endl;

cin>>select;

switch(select){

case 1:{

int start,end;

bool prime=true;

cout<<"enter the first number"<<endl;

cin>>start;

cout<<"enter the end number"<<endl;

cin>>end;

cout<<"the prime numbers between"<<start<<"and"<<end<<"are:"<<endl;


for(int i=start; i<=end;i++){

for(int j=2; j<=sqrt(i);j++){

if(i%j==0)

prime=false;

if(prime==true&& i!=1)

cout<<i<<" ";

prime=true;

break;

case 2:{

int n,r;

cout<<"enter the decimal number\n";

cin>>n;

while(n/2>0){

r=n%2;

cout<<r<<" ";

n=n/2;
}

cout<<1;

break;

case 3:{

char ch;

int a;

do{

cout<<"enter the number to check"<<endl;

cin>>a;

cout<<endl;

if(a%2==0)

cout<<"is even"<<endl;

else

cout<<"is odd"<<endl;

cout<<"do you want to again:y\n"<<endl;

cin>> ch;

while(ch=='y');

break;

case 4:{

int num,s=0,sum=0;

cout<<"enter the number of term"<<endl;

cin>>num;

for(int i=1;i<=num;i++){
s=s*10+1;

cout<<s<<" ";

sum=sum+s;

cout<<"\nthe sum of series="<<sum;

break;

case 5:{

int a;

cout<<"enter the number for checking\n";

cin>>a;

if(per(a)){

cout<<"number"<<a<<"is perfect number"<<endl;

else{

cout<<"number"<<a<<"not perfect number"<<endl;

break;

case 6:{

int num;

cout << "Enter a number: ";

cin >> num;

if (isPalindrome(num)) {

cout << num << " is a palindrome." << endl;

} else {

cout << num << " is not a palindrome." << endl;


}

break;

case 7:{

int arr [100];

int n ;// Size of the array

cout<<"enter the size of array:\n";

cin>>n;

cout<<"enter the elements of array:\n";

for (int i=0; i<n; i++){

cin>>arr[i];

int largest = arr[0];

for (int i = 1; i < n; i++) {

if (arr[i] > largest) {

largest = arr[i];

int second_largest = INT_MIN;

for (int i = 0; i < n; i++) {

if (arr[i] != largest && arr[i] > second_largest) {

second_largest = arr[i];

}
if (second_largest != INT_MIN) {

cout << "The second largest element in the array is: " << second_largest << endl;

} else {

cout << "Error: Array has only one distinct element or an error occurred." << endl;

break;

case 8:{

int n;

cout << "enter the size of array: ";

cin >> n;

int arr[n];

for (int i = 0; i < n; i++) {

cout << "enter the elements of array " << i + 1 << ": ";

cin >> arr[i];

for (int i = 0; i < n; i++) {

for (int j = 0; j < n - i - 1; j++) {

if (arr[j] > arr[j + 1]) {

int temp = arr[j];

arr[j] = arr[j + 1];


arr[j + 1] = temp;

cout << "the array after order it: ";

for (int i = 0; i < n; i++) {

cout << arr[i] << " ";

break;

case 9:{

int numbers[10];

int evencount=0;

int oddcount=0;

cout<<"enter the number to check\n";

for(int i=0; i<10; i++){

cin>>numbers[i];

for(int i=0;i<sizeof(numbers)/sizeof(numbers[10]);i++){

if(numbers[i]%2==0)

evencount++;

else

oddcount++;

cout<<"the even numbers are:\n"<<evencount<<endl;

cout<<"the odd numbers are:\n"<<oddcount<<endl;


}

break;

case 10:{

const int classa=3;

const int columns=3;

int aray[classa][columns];

cout<<"enter"<<classa* columns<<"value of aray of 3*3:"<<endl;

for(int i=0; i<classa; i++){

for(int j=0; j<columns; j++) {

cin>>aray[i][j];

for(int i=0; i<classa; ++i){

int total=0;

for(int j=0; j<columns; j++){

total+=aray[i][j];

cout<<"total items in the row"<<i+1<<"is:"<<total<<endl;

break;

case 11:{

int matrix[3][3];

for (int i = 0; i < 3; i++) {


for (int j = 0; j < 3; j++) {

cout << "Enter the value of element (" << i + 1 << "," << j + 1 << "): ";

cin >> matrix[i][j];

int columnSums[3] = {0};

for (int i = 0; i < 3; i++) {

for (int j = 0; j < 3; j++) {

columnSums[j] += matrix[i][j];

cout << "\nThe matrix:\n";

for (int i = 0; i < 3; i++) {

for (int j = 0; j < 3; j++) {

cout << matrix[i][j] << " ";

cout << endl;

cout << "\nThe column sums:\n";

for (int i = 0; i < 3; i++) {

cout << "Sum of column " << i + 1 << ": " << columnSums[i] << endl;

break;

case 12:{

const int rows=3;


const int cols=3;

int matrix[rows][cols];

cout<<"enter the value for3*3 matrix:\n";

for(int i=0;i<rows;++i){

for(int j=0;j<cols;++j){

cin>>matrix[i][j];

for(int i=0;i<rows;++i){

for(int j=0;j<cols;++j){

if(i+j==cols-1){

matrix[i][j]=-matrix[i][j];

cout<<"\n matrix after change secondary daigonal elements to negative values\n";

for(int i=0;i<rows;++i){

for(int j=0;j<cols;++j){

cout<<matrix[i][j]<<" ";

cout<<endl;

break;

case 13:{
int arr[4];

int array[2][2];

cout<<"enter the value for elements\n";

for(int i=0;i<4;i++)

cin>>arr[i];

int index=0;

for(int i=0;i<2;i++){

for(int j=0;j<2;j++){

array[i][j]=arr[index];

index++;

cout<<"the result is:\n";

for(int i=0;i<2;i++){

for(int j=0;j<2;j++){

cout<< array[i][j]<<"\t";

cout<<"\n";

break;

case 14:

int arr[3][3];

int sum=0;

cout<<"enter the numbers of array3*3\n";


for(int i=0;i<3;i++){

for(int j=0;j<3;j++){

cin>>arr[i][j];

for(int i=0;i<3;i++){

for(int j=0;j<3;j++){

if(i==0||i==2||j==0||j==2)

sum+=arr[i][j];

cout<<"the sum for frontier numbers is:"<<sum<<endl;

break;

case 15:{

int arr1[3][3];

int arr2[3][3];

cout<<"enter the values for array 1:"<<" ";

for(int i=0;i<3;i++){

for(int j=0;j<3;j++){

cin>>arr1[i][j];

cout<<"enter the values for array 2:"<<" ";


for(int i=0;i<3;i++){

for(int j=0;j<3;j++){

cin>>arr2[i][j];

arr2[i][j]+=arr1[i][j];

cout<<"the sum of two arrays is:"<<endl;

for(int i=0;i<3;i++){

for(int j=0;j<3;j++){

cout<<arr2[i][j]<<" ";

cout<<endl;

break;

case 16:{

string inputstring;

cout<<"enter the series of letters:";

getline(cin,inputstring);

int vowelscount=countvowels(inputstring);

cout<<"the count of vowel letters is:"<<vowelscount<<endl;


}

break;

case 17:{

string inputstring;

cout<<"enter the words:"<<endl;

getline(cin,inputstring);

int word = countwords(inputstring);

cout<<"the count of word is:" <<word<<endl;

break;

case 18:{

char str[100];

cout<<" enter the capital characters\n";

[Link](str,100) ;

for(int i=0;i<(str,100);i++){

if(str[i]>='A'&& str[i]<='Z')

str[i]+=32;

cout<<"the small letters is:"<<str<<endl;

break;

case 19:{

char str[100];

cout<<"enter the small characters:\n";

[Link](str,100);

for(int i=0; i<(str,100);i++)

if(str[i]>='a'&& str[i]<='z')
str[i]-=32;

cout<<"the capital letter is:"<<str<<endl;

break;

case 20:{

int size;

cout << "Enter the size of the array: ";

cin >> size;

vector<int> array(size);

for (int i = 0; i < size; i++) {

cout << "Enter element " << i + 1 << ": ";

cin >> array[i];

print_unique_elements(array);

break;

case 21:{

string str;

cout << "Enter a string: ";

getline(cin, str);

cout << "The length of the string is: " << strlength(str) << std::endl;

break;

case 22:{
char original[] = "Hello, World!";

char copy[20];

copyString(original, copy);

cout << "Original string: " << original << endl;

cout << "Copied string: " << copy << endl;

break;

case 23:{

int size;

cout << "Enter the number of elements in the array: ";

cin >> size;

if (size <= 0) {

cout << "Invalid input. Array size must be a positive integer." << endl;

return 1;

int arr[size];

cout << "Enter the array elements: " << endl;

for (int i = 0; i < size; i++) {

cout << "Element " << i + 1 << ": ";

cin >> arr[i];

}
int total = sumArray(arr, size);

cout << "The sum of the array elements is: " << total << endl;

break;

case 24:{

int size;

cout << "Enter the number of elements in the array: ";

cin >> size;

if (size <= 0) {

cout << "Invalid input. Array size must be a positive integer." << endl;

return 1;

int arr[size];

cout << "Enter the array elements: " << endl;

for (int i = 0; i < size; i++) {

cout << "Element " << i + 1 << ": ";

cin >> arr[i];

}
int numToSearch;

cout << "Enter the element to search for: ";

cin >> numToSearch;

bool found = searchElement(arr, size, numToSearch);

if (found) {

cout << "The element " << numToSearch << " was found in the array." << endl;

} else {

cout << "The element " << numToSearch << " was not found in the array." << endl;

break;

case 25:{

int size, key;

cout<<"enter thr size of array:";

cin>>size;

int arr[size];

cout<<"enter"<<size<<"elements of array:";

for(int i=0;i<size;i++){

cin>>arr[i];

cout<<"enter the element to search for:";

cin>>key;

if(searchelement(arr,size,key)){
cout<<"element found in the array."<<endl;

else{

cout<<"element not found in the array."<<endl;

break;

default:

cout<<"error";

return 0;

You might also like