Write a program to create a dynamic array of user defined size. Array should be of character type. Write a function ChangeCase() that should convert all the small alphabets to capital and vice versa. All array operations should be done using pointers
#include<iostream>
using namespace std;
void ChangeCase(char str[], int n)
{
for (int i = 0; i < n; i++) {
if (str[i] >= 'a' && str[i] <= 'z')
str[i] = str[i] - 32;
else if (str[i] >= 'A' && str[i] <= 'Z')
str[i] = str[i] + 32;
}
}
int main(){
cout<<"Enter the size of the array:\n";
int n;
cin>>n;
char letters[n];
cout<<"Enter the string\n";
cin>>letters;
ChangeCase(letters,n);
cout<<letters<<endl;
}
Comments
Leave a comment