Question

Please write a code in C: As a young kid, Kiki likes to learn something new....

Please write a code in C:

As a young kid, Kiki likes to learn something new. His Sister, Lala, gave 3 distinct alphabet blocks to Kiki. Kiki likes these blocks so much. Kiki also likes to help her sister to tidy up Lala's bookshelf. Even, Kiki can sorts those books from the smallest book to the biggest book easily. She just wonder if she can sort those alphabet blocks. Then, Kiki asked her sister about it, and she said that those blocks can be sorted in alphabetical order (A, B, ... , Y, Z). Unfortunately, Kiki still does not understand about alphabet. But, she really want to sort those 3 blocks alphabetically. You can help her sort the 3 alphabet blocks by telling her which block should be placed first. Help her to realize her desire to sort the alphabet blocks she had.

Format Input

Given one line consists of 3 character (one character long each) x1, x2, x3 - alphabet written on block number 1, 2, and 3.

Format Output

Output a single line that contains the order how to sort those blocks into alphabetical order

Constraints

• A ≤ x1, x2, x3 ≤ Z

Sample Input 1 (standard input)

B D A

Sample Output 1 (standard output)

3 1 2

Sample Input 2 (standard input)

A B C

Sample Output 2 (standard output)

1 2 3

Explanation

For Sample Test Case 1, given letter B, D, A and by alphabetical order, those letter should be sorted as A, B, D. Block A which located on 3rd position should be placed first, Block B is on 1st position, and then Block D is on 2nd position. Thus, the answer is 3 1 2.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

//DRIVER FUNCTION
int main(void) {
  char game[4];
  char ch, temp;
  int arr[4],i,j,tem;
  
  printf("You have to enter three alphabets in block letter :\n");
  for(i=1; i<=3; i++){
    int flag = 0;
    //LOOP TO TAKE 
    while(flag!=1){
      printf("Enter alphabet number %d :", i);
      fflush(stdin);
      scanf("%c",&ch);
      if(ch>='A' && ch<='Z'){
        game[i] = ch;
        flag =1; 
        arr[i] = i;
        break;
      }
      else{
        printf("Input character is wrong, enter capital lettered alphabet.\n");
      }
    }
  }
  //print the input string
  printf("Input :\n");
  for(i=1;i<=3;i ++)
    printf("%c\t", game[i]);
    
  //sorting alphabetically 
  for(i=1;i<=2;i++){
    for(j=i+1;j<=3;j++){
      if(game[i]>game[j]){
        temp = game[i];
        game[i]= game [j];
        game[j] = temp;
        
        tem = arr[i];
        arr[i] = arr[j];
        arr[j] = tem;
      }
    }
  }
  printf("\nOutput :\n");
  for(i=1;i<=3;i++)
    printf("%d\t",arr[i]);
}

OUTPUT :

A D:\rkmrciHomeworkLib\kiki.exe You have to enter three alphabets in block letter : Enter alphabet number 1 : Enter alphabet numberD:\rkmrc\HomeworkLib\kiki.exe You have to enter three alphabets in block letter : 1 Enter alphabet number 1 :b Input character is w

Add a comment
Know the answer?
Add Answer to:
Please write a code in C: As a young kid, Kiki likes to learn something new....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C++ program that reads in a text file and writes the histogram of character counts sorted in alphabetical order to an output file. Eg, if the input file is “to be or not to be”, then the output should be: b **2 e **2 n *1 o ****4

    Write a C++ program that reads in a text file andwrites the histogram of character counts sorted inalphabetical order to an output file. Eg, if theinput file is “to be or not to be”, then the outputshould be:b   **2e   **2n   *1o   ****4r    *1t    ***3

  • Write a C++ code to make a simple program that imports the input file in and...

    Write a C++ code to make a simple program that imports the input file in and gets the results as specified Please follow the instructions and paste the code below as the answer with a screenshot of the output to prove it worked. Input file -> https://www.dropbox.com/s/444jofkchu6ylwr/names.txt?dl=0 Scoring Names You will be using the provided names.txt file, text file containing over five-thousand first names, and you will calculate a score for each name. Begin by reading the names from the...

  • LANGUAGE = C i. Write a program that takes int numbers from user until user gives...

    LANGUAGE = C i. Write a program that takes int numbers from user until user gives a sentinel value (loop terminating condition). Sort the numbers in ascending order using Insertion sort method. Sorting part should be done in different function named insertionSort(). Your code should count the number of swaps required to sort the numbers. Print the sorted list and total number of swaps that was required to sort those numbers. (4 marks) ii. In this part take another number...

  • I need eclipse code for : Write a program that analyzes text written in the console...

    I need eclipse code for : Write a program that analyzes text written in the console by counting the number of times each of the 26 letters in the alphabet occurs. Uppercase and lowercase letters should be counted together (for example, both ‘A’ and ‘a’ should count as an A). Any characters that are not letters should be ignored. You must prompt the user to enter the text to be analyzed. Then, for any letter that appeared at least once...

  • In C programming please (b) You will write a program that will do the following: prompt...

    In C programming please (b) You will write a program that will do the following: prompt the user enter characters from the keyboard, you will read the characters until reading the letter 'O' You will compule statistics concerning the type of characters entered. In this lab we will use a while loop. We will read characters from stdin until we read the character 'Q' Example input mJ0*5/1+x1@3qcxQ The 'Q' should be included when computing the statistics properties of the input....

  • This is for C++ Write a program that reads in a sequence of characters entered by...

    This is for C++ Write a program that reads in a sequence of characters entered by the user and terminated by a period ('.'). Your program should allow the user to enter multiple lines of input by pressing the enter key at the end of each line. The program should print out a frequency table, sorted in decreasing order by number of occurences, listing each letter that ocurred along with the number of times it occured. All non-alphabetic characters must...

  • 1) Echo the input: First, you should make sure you can write a program and have...

    1) Echo the input: First, you should make sure you can write a program and have it compile and run, take input and give output. So to start you should just echo the input. This means you should prompt the user for the plaintext, read it in and then print it back out, with a message such as "this is the plaintext you entered:". [4 points, for writing a working program, echoing the input and submitting the program on the...

  • Write Java code to implement a FSM machine that recognizes the language for the alphabet {a,b,c} ...

    Write Java code to implement a FSM machine that recognizes the language for the alphabet {a,b,c} consisting of all strings that contain two consecutive c's and end with b.                   Your FSM program should include the following three static methods (Java) or functions (C):                                           a.    int nextState(int state, char symbol)                                  A state-transition function that returns the next state based on the                                  current state and an input symbol. This function should also return                                  -1 when an invalid input character is detected.                                  State...

  • In basic c develop the code below: (a) You will write a program that will do...

    In basic c develop the code below: (a) You will write a program that will do the following: prompt the user enter characters from the keyboard, you will read the characters until reading the letter ‘X’ You will compute statistics concerning the type of characters entered. In this lab we will use a while loop. We will read characters from stdin until we read the character ‘X’. Example input mJ0*5/]+x1@3qcxX The ‘X’ should not be included when computing the statistics...

  • Hi, it's C++ question. Only can use <iostream> and <fstream>libraries Please help me, thanks Question Description:...

    Hi, it's C++ question. Only can use <iostream> and <fstream>libraries Please help me, thanks Question Description: For this project you will write a program to: a) read-in the 10 first names from a file (the file is a priori given to have exactly 10 entries, of a maximum length of 8 letters each) into a 2-dimensional character array, b) output the names to the terminal with each one preceded by a number indicating its original order in the list, c)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT