C Programming Language
2nd Edition
ISBN: 9780131103627
Author: Brian W. Kernighan, Dennis M. Ritchie, Dennis Ritchie
Publisher: Prentice Hall
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 1, Problem 20E
Write a
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
In Python, The function concatAltChars takes a string parameter s and a boolean parameter even; the function concatenates together either the even-position characters of s or the odd-position characters of s, depending on whether even is True, or False, respectively. The accumulated string is returned.
For example, the even-indexed characters of "HANOVER" are at indexes 0, 2, 4, and 6: H N V R. So, concatAltChars("HANOVER", True) returns the string result "HNVR".
But concatAltChars("HANOVER", False) returns the string result "AOE".
For example:
Test
Result
s = "goldfinches" print(concatAltChars(s, True))
glfnhs
s = "A" print(concatAltChars(s, True))
A
s = "A" print(concatAltChars(s, False))
Program a simplified Galton board in python. It is required that:
The user must select the number of rows n of the board
The distribution resulting from dropping the beads should be displayed on the screen.
Display an animation where the number of rows n increases over time.All resulting distributions must be scaled to the interval [0, 1], so that it is possible toappreciate the convergence to the normal distribution. Consider n from 1 to 80.
In Python, with use of function and input parsing/
Make a method is_anagram_of(a,b) that tests if a is an anagram of b. A string a is an anagram of a string b, if it uses exactly the same letters, but the order can be different. Spaces are ignored, as well as capitalization.
Examples of anagrams:
"eleven plus two" - "twelve plus one"
"William Shakespeare" - "I am a weakish speller"
"Tom Marvolo Riddle" - "I am Lord Voldemort"
"Anagrams" - "Ars manga"
"television ads" - "enslave idiots"
Counter examples:
"bla" - "aalb"
"cat" - "tact"
Hint: Make a dictionary that holds how often a letter occurs in a word.
Chapter 1 Solutions
C Programming Language
Ch. 1 - Run the hello, world program on your system....Ch. 1 - Prob. 2ECh. 1 - Modify the temperature conversion program to print...Ch. 1 - Write a program to print the corresponding Celsius...Ch. 1 - Prob. 5ECh. 1 - Prob. 6ECh. 1 - Write a program to print the value of EOF.Ch. 1 - Write a program to count blanks, tabs and...Ch. 1 - Write a program to copy its input to its output,...Ch. 1 - Write a program to copy its input to its output,...
Ch. 1 - Prob. 11ECh. 1 - Write a program that prints its input one word per...Ch. 1 - Write a program to print a histogram of the...Ch. 1 - Write a program to print a histogram of the...Ch. 1 - Rewrite the temperature conversion program of...Ch. 1 - Revise the main routine of the longest-line...Ch. 1 - Write a program to print all input lines that are...Ch. 1 - Write a program to remove trailing blanks and tabs...Ch. 1 - Write a function reverse(s) that reverses the...Ch. 1 - Write a program detab that replaces tabs in the...Ch. 1 - Write a program entab that replaces strings of...Ch. 1 - Write a program to fold long input lines into two...Ch. 1 - Prob. 23ECh. 1 - Write a program to check a C program for...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
In programming we use the term string to mean _____. a. many lines of code b. parallel memory locations c. stri...
Starting Out With Visual Basic (8th Edition)
The hypotenuse example script truncates the sides to integers, but outputs a floating-point number. Why? Adapt ...
Computer Science: An Overview (12th Edition)
Write a program that inputs two strings (either C-string or STL string) that represents a time of day using the...
Problem Solving with C++ (10th Edition)
The following program skeleton, when completed, will ask the user to enter 10 integers, which are stored in an ...
Starting Out with C++ from Control Structures to Objects (8th Edition)
Open the house project from Chapter 1 and review the Picture class. What types of object are created by the con...
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
How does method overloading improve the usefulness of a class?
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Write in JAVA When analyzing data sets, such as data for human heights or for human weights, a common step is to adjust the data. This adjustment can be done by normalizing to values between 0 and 1, or throwing away outliers. For this program, adjust the values by dividing all values by the largest value. The input begins with an integer indicating the number of floating-point values that follow. Assume that the list will always contain fewer than 20 floating-point values. Output each floating-point value with two digits after the decimal point, which can be achieved as follows:System.out.printf("%.2f", yourValue);arrow_forwardScrabble is a word game in which words are constructed from letter tiles, each letter tile containing a point value. The value of a word is the sum of each tile's points added to any points provided by the word's placement on the game board. Write a program using the given dictionary of letters and point values that takes a word as input and outputs the base total value of the word (before being put onto a board). Ex: If the input is: PYTHON the output is: 14 tile_dict = { 'A': 1, 'B': 3, 'C': 3, 'D': 2, 'E': 1, 'F': 4, 'G': 2, 'H': 4, 'I': 1, 'J': 8, 'K': 5, 'L': 1, 'M': 3, 'N': 1, 'O': 1, 'P': 3, 'Q': 10, 'R': 1, 'S': 1, 'T': 1, 'U': 1, 'V': 4, 'W': 4, 'X': 8, 'Y': 4, 'Z': 10 } ''' Type your code here. '''arrow_forwardUse Python for this question: Implement a function findMixedCase that accepts a single argument, a list of words, and returns the index of the first mixed case word in the list, if one exists, (a word is mixed case if it contains both upper and lower case letters), and returns -1 if the all words are either upper or lower case Output for this question is in the attached image:arrow_forward
- Scrabble is a word game in which words are constructed from letter tiles, each letter tile containing a point value. The value of a word is the sum of each tile's points added to any points provided by the word's placement on the game board. Write a program using the given dictionary of letters and point values that takes a word as input and outputs the base total value of the word (before being put onto a board). Ex: If the input is: PYTHON the output is: 14arrow_forwardScrabble is a word game in which words are constructed from letter tiles, each letter tile containing a point value. The value of a word is the sum of each tile's points added to any points provided by the word's placement on the game board. Write a program using the given dictionary of letters and point values that takes a word as input and outputs the base total value of the word (before being put onto a board). Ex: If the input is: PYTHON the output is: PYTHON is worth 14 points. 461710.3116374.qx3zqy7 LAB ACTIVITY 1 tile_dict = { 'A': 1, 'B': 3, 'K': 5, 'L': 1, 'U': 1, 'V': 4, 12345 2 3 6.27.1: LAB: Scrabble points 4 5'' Type your code here. 111 'C': 3, 'D': 2, 'M': 3, 'N': 1, 'W': 4, 'X': 8, main.py 'E': 1, 'F': 4, '0': 1, 'P': 3, 'Y': 4, 'Z': 10 } 0/10 Load default template... 'G': 2, 'H': 4, 'I': 1, 'J': 8, 'Q': 10, 'R': 1, 'S': 1, 'T': 1,arrow_forwardPython Scrabble is a word game in which words are constructed from letter tiles, each letter tile containing a point value. The value of a word is the sum of each tile's points added to any points provided by the word's placement on the game board. Write a program using the given dictionary of letters and point values that takes a word as input and outputs the base total value of the word (before being put onto a board). Ex: If the input is: PYTHON the output is: 14 part of the code: tile_dict = { 'A': 1, 'B': 3, 'C': 3, 'D': 2, 'E': 1, 'F': 4, 'G': 2, 'H': 4, 'I': 1, 'J': 8, 'K': 5, 'L': 1, 'M': 3, 'N': 1, 'O': 1, 'P': 3, 'Q': 10, 'R': 1, 'S': 1, 'T': 1, 'U': 1, 'V': 4, 'W': 4, 'X': 8, 'Y': 4, 'Z': 10 }arrow_forward
- The government publishes a list of the 10,000 most popular baby names along with their frequency each year (the number of babies with that name). This only has a problem with some names having different spellings. For instance, even if "John" and ".Jon" have almost the same name, they are included individually in the list. Write an algorithm to print a new list of the true frequencies of each name from two lists: one of names/frequencies and the other of pairings of equivalent names. Be aware that John and Johnny are synonyms if John and Jon are as well as Jon and Johnny. (It is symmetric and transitive.) Any name may be used as the "actual" name on the final list. EXAMPLEInput:Names: John (15), Jon (12), Chris (13), Kris (4), Christopher (19)Synonyms: (Jon, John), (John, Johnny), (Chris, Kris), (Chris, Christopher)Output: John (27), Kris (36)arrow_forwardImplement a function, countVowels, which takes in a string and counts the number of vowels that are contained within it. Make sure that both capital vowels and lowercase vowels are counted. Your starter code contains a main function, which asks for user input and outputs the number of vowels. You will need to implement the user input for the string. Sample Runs (user input is italicized and underlined): Enter a phrase: Hello World!Number of vowels: 3 Enter a phrase: PROGRAMMING IS EXCELLENT.Number of vowels: 7 #include <string>#include <iostream>using namespace std; int countVowels(string word); int main(){ string phrase; cout << "Enter a phrase: "; // To do: implement user input cout << "Number of vowels: " << countVowels(phrase) << endl;} // To do: Implement countVowels int countVowels(string word){}arrow_forwardWrite a Python program that prompts the user to enter a list of words and stores in a list only those words whose first letter occurs again within the word (for example, 'Baboon'). The program should display the resulting list. NOTE: 'Baboon' starts with a capital letter and should be included in the list (therefore, the test is not case-sensitive). When you print the word list, ensure you maintain case-sensitivity; i.e. Both 'Baboon' and 'baboon' should be in the list that prints out, if they were provided as input by the user.arrow_forward
- Implement the vacuum cleaning agent function in Python/Java for the scenario described below: Consider two-dimensional Boolean array of size m x n (m and n can each be equal to 4) where m is the number of rows, and n is the number of columns. Obtain numerical positive integer values for m and n as inputs from the user. Generate random numbers and scale them down to either a “0” or a “1” according to whether they represent “Clean” or “Dirty”, respectively. After filling the array with 0s or 1s, start at some random array position indicating the initial position of the vacuum cleaner. First check if at that current position, there is the presence of a “Dirt” or not determined by whether 0 or 1 is filled in at that initial position of the vacuum cleaner. If there is a “Dirt”, clean it, and if there is no “Dirt” do a No-operation. After this is done, generate random numbers modulo 4 to obtain random numbers 0, 1, 2, 3 indicating whether to take a left, right, up or down correspondingly. If…arrow_forwardMake Camel Case. Create a program that reads a multi-word phrase, and prints the Camel Case equivalent. For example, for input “total account balance” the program shall output “totalAccountBalance”.Notice that the first word is in lowercase (even if it contains uppercase letters). The rest of the words, only their initials are capitalized.arrow_forwardWrite a program to remove all punctuation marks from an inputted message. The program should read an input message from a user into an array of characters; it should then modify the contents of the message, so that all punctuation marks are removed; and finally it should print out the modified message using a single printf statement. If the user types: Too, many, punctuation marks:; by far!! the program should output Too many punctuation marks by far For the purposes of this question, a punctuation mark is any one of the following seven characters !’?;:,. For example: Input Result Too, many, punctuation marks:; by far!! Too many punctuation marks by far Hyphen "-" survives ; why? as it is not one of the listed punctuation marks. Hyphen "-" survives why as it is not one of the listed punctuation marks Code I was given: #include <stdio.h>#define MAX_MSG_LEN 256 int main(void){ char msg[MAX_MSG_LEN+1]; fgets(msg, MAX_MSG_LEN, stdin); /* write your solution…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY