C++ Program to Convert String to Upper Case, Lower Case and Toggle Case
Write C++ Program to Convert String to Upper Case, Lower Case and Toggle Case
// CPP Program to Convert String to Upper Case, Lower Case and Toggle Case #include <iostream> #include <string.h> using namespace std; int main() { char S[] = "Hello and Welcome To Codecrucks", c; int i=0; cout << "Original String :--> " << S; cout << "\n\nUpper Case :--> "; while(S[i] != '\0') //TO CONVERT INTO THE UPPER CASE { if(S[i] >= 'a' && S[i] <= 'z') { c = S[i] - 32; cout << c; } else cout << S[i]; i++; } i = 0; cout << "\nLower Case :--> "; while(S[i] != '\0') //TO CONVERT INTO THE UPPER CASE { if(S[i] >= 'A' && S[i] <= 'Z') { c = S[i] + 32; cout << c; } else cout << S[i]; i++; } i = 0; printf("\nToggle Case :--> "); while(S[i] != '\0') //TO CONVERT INTO THE UPPER CASE { if(S[i] >= 'A' && S[i] <= 'Z') { c = S[i] + 32; cout << c; } else if(S[i] >= 'a' && S[i] <= 'z') { c = S[i] - 32; cout << c; } else printf("%c", S[i]); i++; } return 0; }
Output:
Original String :--> Hello and Welcome To Codecrucks
Upper Case :--> HELLO AND WELCOME TO CODECRUCKS
Lower Case :--> hello and welcome to codecrucks
Toggle Case :--> hELLO AND wELCOME tO cODECRUCKS