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

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++ 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...
Write a C program that prompt the user to enter 10 numbers andstores the numbers...
Write a C program that prompt the user to enter 10 numbers and stores the numbers in an array. Write a function, smallestIndex, that takes as parameters an int array and its size and return the index of the first occurrence of the smallest element in the array.The main function should print the smallest number and the index of the smallest number.
Write a C++ program that prompt the user to enter 10 numbers andstores the numbers...
Write a C++ program that prompt the user to enter 10 numbers and stores the numbers in an array. Write a function, smallestIndex, that takes as parameters an int array and its size and return the index of the first occurrence of the smallest element in the array.The main function should print the smallest number and the index of the smallest number.
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...
C++ Code Writing prompt: Grade Calculation: Write a program that asks the user to enter in...
C++ Code Writing prompt: Grade Calculation: Write a program that asks the user to enter in a number greater than or equal to zero and less than or equal to 100. If they do not you should alert them and end the program. Next, determine the letter grade associated with the number. For example, A is any grade between 90 and 100. Report the letter grade to the user.
Program should be written in Java b) The computer program should prompt the user (You are...
Program should be written in Java b) The computer program should prompt the user (You are the user) to enter the answers to the following questions: What is your city of birth? What is your favorite sport? If you could live anywhere in the world, where would you like to live? What is your dream vacation? Take this information and create a short paragraph about the user and output this paragraph. You may use the Scanner class and the System.out...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT