help visual studios program

Declare a character array, and initialize it to a suitable string. Use a loop to change every other
character to uppercase.
Hint: In the ASCII character set, values for uppercase characters are 32 less than their lowercase
counterparts.


Please write a string/array program to fulfill this prompt
without using pointer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include<iostream>
using namespace std;

int main()
{
    char arr[5];
    cin>>arr;
    for(int i=0;i<5;i++)
    {
        arr[i]=arr[i]-32;
    }
    cout<<arr;
    return 0;
}


using pointer


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream>
using namespace std;

int main()
{
    char* arr;
    int size=0;
    cout<<"\nEnter The Size Of The Char Array : ";
    cin>>size;
    arr=new char[size];
    cout<<"\nEnter The Char Without Going in Next Line : ";
    cin>>arr;
    for(int i=0;i<size;i++)
    {
        arr[i]=arr[i]-32;
    }
    cout<<arr;
    delete[] arr;
    return 0;
}




Enter The Size Of The Char Array : 5

Enter The Char Without Going in Next Line : abcde
ABCDE


OR
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<iostream>
using namespace std;

int main()
{
    char arr[256];
    int size=0;
    cout<<"\nEnter The Size Of The Char Array : ";
    cin>>size;
    for(int i=0;i<size;i++)
    {
        cin>>arr[i];
    }
    
    for(int i=0;i<size;i++)
    {
        arr[i]=arr[i]-32;
    }
    
    
    for(int i=0;i<size;i++)
    {
        cout<<" "<<arr[i]<<" ";
    }
        
    
    return 0;
}







Enter The Size Of The Char Array : 5
a
b
c
d
e
 A  B  C  D  E




Thank you so much for the help. Much appreciated.
Topic archived. No new replies allowed.