Knowee
Questions
Features
Study Tools

Develop a C program that reads the city name and state name from theuser as two different strings. Merge them into a new string (format iscityname@@statename) and display it.Example:Input: Enter city name and state name: Hyderabad TelanganaOutput: Hyderabad@@Telangana

Question

Develop a C program that reads the city name and state name from theuser as two different strings. Merge them into a new string (format iscityname@@statename) and display it.Example:Input: Enter city name and state name: Hyderabad TelanganaOutput: Hyderabad@@Telangana

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a step-by-step guide to develop a C program that reads the city name and state name from the user and merges them into a new string:

  1. Start by including the necessary header files:
#include <stdio.h>
#include <string.h>
  1. Declare a function to merge the city name and state name:
void mergeStrings(char city[], char state[], char mergedString[]);
  1. Implement the mergeStrings function:
void mergeStrings(char city[], char state[], char mergedString[]) {
    // Copy the city name to the merged string
    strcpy(mergedString, city);
    
    // Append "@@" to the merged string
    strcat(mergedString, "@@");
    
    // Append the state name to the merged string
    strcat(mergedString, state);
}
  1. In the main function, declare variables to store the city name, state name, and merged string:
int main() {
    char city[100];
    char state[100];
    char mergedString[200];
    
    // Read the city name and state name from the user
    printf("Enter city name: ");
    scanf("%s", city);
    
    printf("Enter state name: ");
    scanf("%s", state);
    
    // Call the mergeStrings function to merge the city and state names
    mergeStrings(city, state, mergedString);
    
    // Display the merged string
    printf("Merged string: %s\n", mergedString);
    
    return 0;
}
  1. Compile and run the program. Enter the city name and state name when prompted, and the program will display the merged string.

That's it! You have successfully developed a C program that reads the city name and state name from the user, merges them into a new string, and displays it.

This problem has been solved

Similar Questions

Problem StatementWrite a query to retrieve the names and cities of employees who are located either in New York or San Francisco from the Employee table.Table name: EmployeeInput records:Input format :The input table is already created, and records are already prepopulated, as mentioned in the problem statement.Output format :The output displays a list of names and corresponding cities of employees who reside in New York or San Francisco as shown below.name cityMary New YorkEmily New YorkSteven San FranciscoRefer to the sample output for the column headers.Note :The program will be evaluated only after the “Submit Code” is clicked.Extra spaces and new line characters in the program output will result in the failure of the test case.

Query the list of CITY names starting with vowels (i.e., a, e, i, o, or u) from STATION. Your result cannot contain duplicates.Input Format

Query the list of CITY names ending with vowels (a, e, i, o, u) from STATION. Your result cannot contain duplicates.Input Forma

Write a function that reads your name in lowercase and perform the following operationprints it in uppercaseprints the length of the nameSample Inputsanjay kumarSample OutputSANJAY KUMAR12

Query the list of CITY names from STATION which have vowels (i.e., a, e, i, o, and u) as both their first and last characters. Your result cannot contain duplicates.Input FormatThe STATION table is described as follows:

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.