Pages

Sunday, April 20, 2025

Character Conversion to Uppercase in C++

 #include <iostream>

#include <cstring>

using namespace std;


void toUpper(char word[], int n) {

    

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

        char ch = word[i];

        if(ch >= 'A' && ch <= 'Z') { // uppercase

            continue;

        }

        else { // lowercase

            word[i] = ch - 'a' + 'A';

        }

    }

}


int main() {

    char word[] = "abcde";

    toUpper(word, strlen(word));


    cout << word << endl;

    return 0;

}

No comments:

Post a Comment

Stack using Linked List – Partial (University Exam Topic)

 #include <iostream> using namespace std; struct Node {     int data;     Node* next; }; class Stack {     Node* top; public:     Stac...