String Concatenation and Uppercase Conversion

Algorithm

Step 1: Start

Step 2: Declare two strings, ch and ch2

Step 3: Concatenate the strings ch and ch2 using strcat()

Step 4: Convert each character in the concatenated string to uppercase using toupper()

Step 5: Print the resulting string

Step 6: End

Flowchart

graph TD; A([Start]) --> B[/Declare strings ch and ch2/]; B --> C[Concatenate ch and ch2]; C --> D[Convert concatenated string to uppercase]; D --> E[/Print final result/]; E --> F([End]); %% Define styles classDef start fill:#00cc44,stroke:#006622,stroke-width:2px,color:#ffffff; classDef stop fill:#ff4444,stroke:#cc0000,stroke-width:2px,color:#ffffff; classDef input_output fill:#ffdd44,stroke:#cc9900,stroke-width:2px,color:#000000; classDef process fill:#4488ff,stroke:#0044cc,stroke-width:2px,color:#ffffff; classDef decision fill:#ff8844,stroke:#cc4400,stroke-width:2px,color:#ffffff; %% Apply styles class A start; class F stop; class B,E input_output; class C,D process;

Program

#include<stdio.h>
#include<string.h>
#include<ctype.h> // For toupper()

int main()
{
    char ch[20] = "hello";   // Allocate enough space for the concatenated string
    char ch2[] = "MECH";      // Automatically sizes the second string

    // Concatenate strings
    strcat(ch, ch2);

    // Convert the concatenated string to uppercase using a loop
    for (int i = 0; ch[i] != '\0'; i++)
    {
        ch[i] = toupper((unsigned char) ch[i]);
    }

    // Print result
    printf("Value of first string is: %s\n", ch);

    return 0;
}
                

Test Case Output
Value of first string is: HELLOMECH