Question

In: Computer Science

write a program to perform the following in C Your program should prompt the user to...

write a program to perform the following in C

    • Your program should prompt the user to enter ten words, one at a time, which are to be stored in an array of strings.
    • After all of the words have been entered, the list is to be reordered as necessary to place the words into alphabetical order, regardless of case.
    • Once the list is in alphabetical order, the list should be output to the console in order.
    • The program should execute on a FRDM KL46Z board

Solutions

Expert Solution

If you have any doubts, please give me comment...

#include <stdio.h>

#include <string.h>

int main()

{

    const int n = 10;

    char words[n][50], temp[50];

    int i, j;

    printf("Enter 10 words:\n");

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

        scanf("%s", words[i]);

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

    {

        for (j = i + 1; j < n; j++)

        {

            if (strcmp(words[i], words[j]) > 0)

            {

                strcpy(temp, words[i]);

                strcpy(words[i], words[j]);

                strcpy(words[j], temp);

            }

        }

    }

    printf("\nAfter sorting strings in alphabetical order is:\n");

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

        printf("%s\n", words[i]);

    }

    return 0;

}

Let me know, if you are facing any errors. Thank you...


Related Solutions

Write a C program Your program will prompt the user to enter a value for the...
Write a C program Your program will prompt the user to enter a value for the amount of expenses on the credit card. Retrieve the user input using fgets()/sscanf() and save the input value in a variable. The value should be read as type double. The user may or may not enter cents as part of the input. In other words, expect the user to enter values such as 500, 500.00 and 500.10. The program will then prompt the user...
C++. Write a program that uses for loops to perform the following steps: a. Prompt the...
C++. Write a program that uses for loops to perform the following steps: a. Prompt the user to input two positive integers. variables: firstNum and secondNum (firstNum must be less than secondNum). Validate the user's input; prompt the user again if firstNum is not less than secondNum (use for loop). b. Output all odd numbers between firstNum and secondNum. (use for loop). c. Output the sum of all even numbers between firstNum and secondNum. (use for loop). d. Output the...
IN C This assignment is to write a program that will prompt the user to enter...
IN C This assignment is to write a program that will prompt the user to enter a character, e.g., a percent sign (%), and then the number of percent signs (%) they want on a line. Your program should first read a character from the keyboard, excluding whitespaces; and then print a message indicating that the number must be in the range 1 to 79 (including both ends) if the user enters a number outside of that range. Your program...
Write a program that calculates the salary of employees. The program should prompt the user to...
Write a program that calculates the salary of employees. The program should prompt the user to enter hourly rate and number of hours of work a day. Then, the program should display the salary daily, bi-weekly (5 days a week), and monthly. Sample program: Enter your hourly rate: >>> 20 Enter how many hours you work a day: >>> 8 Your daily salary is: $160 Your bi-weekly salary is: $1600 Your monthly: $3200
Write a C++ program performing the rot13 cipher, The code should perform like this: The user...
Write a C++ program performing the rot13 cipher, The code should perform like this: The user should be able to input any letter or words, or even sentences where once they have inputted the particular word, each letter goes 13 letters ahead, so an 'A' becomes an 'N', a 'C' becomes 'P', and so on. If rot13 cipher is tested a second time, the original plantext should be restored: 'P' becomes 'C', 'N' becomes 'A'. The 13 letters go in...
C++ code a program should prompt the user for the name of the output file. The...
C++ code a program should prompt the user for the name of the output file. The file should be opened for write operations. Values calculated by the program will be written to this file. The program must verify that the file opened correctly. If the file did not open, an error message should be printed and the user should be prompted again. This should continue until the user supplies a valid filename.
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                       ...
C++ PLEASE Write a program to prompt the user to display the following menu: Guess-Number                        Concat-names             Quit If the user selects Guess-number, your program needs to call a user-defined function called int guess-number ( ). Use random number generator to generate a number between 1 – 100. Prompt the user to guess the generated number and print the following messages. Print the guessed number in main (): Guess a number: 76 96: Too large 10 Too small 70 Close...
1. Write a program in C++ to find the factorial of a number. Prompt the user...
1. Write a program in C++ to find the factorial of a number. Prompt the user for a number and compute the factorial by using the following expression. Use for loops to write your solution code. Factorial of n = n! = 1×2×3×...×n; where n is the user input. Sample Output: Find the factorial of a number: ------------------------------------ Input a number to find the factorial: 5 The factorial of the given number is: 120 2. Code problem 1 using While...
Write a C++ Program. Include the Homework header. Then prompt the user for a temperature that...
Write a C++ Program. Include the Homework header. Then prompt the user for a temperature that is in Fahrenheit for some water. Input the temperature (either an int or a double).   then output one of three statements: if the temperature is below 32 degrees or below tell them it is ice. For example if they input 22 then the output would be: At a temperature of 22 degrees the water would take the form of ice. if the temperature is...
Your Java program should perform the following things:Take the input from the user about the...
Your Java program should perform the following things:Take the input from the user about the patient name, weight, birthdate, and height.Calculate Body Mass Index.Display person name and BMI Category.If the BMI Score is less than 18.5, then underweight.If the BMI Score is between 18.5-24.9, then Normal.If the BMI score is between 25 to 29.9, then Overweight.If the BMI score is greater than 29.9, then Obesity.Calculate Insurance Payment Category based on BMI Category.If underweight, then insurance payment category is low.If Normal...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT