[Solved] CS1114-Homework 5- Ask user to input a positive integer n

$25

File Name: CS1114-Homework_5-_Ask_user_to_input_a_positive_integer_n.zip
File Size: 536.94 KB

SKU: [Solved] CS1114-Homework 5- Ask user to input a positive integer n Category: Tag:
5/5 - (1 vote)

Homework #5

Question 1:Ask user to input a positive integer n. Your program should print the first n odd numbers.For example, one execution would look like this:Please enter a positive integer: 3135

Question 2:Ask user to input a positive integer n, and print a textual image of an hourglass made of 2n lines with asterisks.For example if n=4, the program should print:******************************* *Question 3:Ask user to input a string containing only lower case letters. Determine if the input is ordered ina lexicographical increasing order.For example, an execution would look like: Please enter a string of lowercase letters: abgkp a bg k p is increasing.Another execution would look like:Please enter a string of lowercase letters: abgcp a bgc p is not increasing.Question 4:Write a program that asks user to input a positive integer n and print out the Roman numeral for n. Your program should be general enough to work with any positive integer n.Recall from Lab 3, the rules for Roman numeral are:Number is a combination of the special characters.Decimal 1 5 10 50 100 500 1000Roman I V X L C D M

In this question, use the non-standard form of Roman numerals. For example, if n = 4, print out: IIII (and not IV). If n = 44, print out: XXXXIIII (and not XLIV). Etc.

Question 5:Write two versions of a program that reads a sequence of positive integers from the user, calculates their geometric mean, and print the geometric mean.Note: In mathematics, geometric mean of a dataset 1,2,3, is givenby: 123~.For example, the geometric mean of 2, 9 and 12 is equal to 6 (29123 =6).Your two versions of the program should read the integer sequence in two ways:a) First read the length of the sequence For example, an execution would look like:Please enter the length of the sequence: 3Please enter a positive integer: 1 Please enter a positive integer: 2 Please enter a positive integer: 3 The geometric mean is: 1.8171 b ) Keep reading the numbers until Done is entered.For example, an execution would look like:Please enter a positive integer: 1 Please enter a positive integer: 2 Please enter a positive integer: 3 Please enter a positive integer: Done The geometric mean is: 1.8171Question 6Ask user to input a line of text, and a character ch. Your program should:1 . Create a string variable that contains the text after removing all occurrences of the character ch from the input text.2 . Print that string.For example, an execution would look like:Please enter a line of text: This is a line of text.Please enter the character you want to remove: sT h i i a line of text.

Question 7:Ask user to input a positive integer n, and print all of the numbers from 1 to n that have more even digits than odd digits.For example, if n=30, the program should print:246820 22 24 26 28Question 8:Ask user to input a positive integer n, and print a triangle of numbers aligned to the right, where the first line contains the number 1. The second line contains the numbers 1,2. The third line contains 1,2,3. And so on.For example if n=5, the program should print:112123123412345

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CS1114-Homework 5- Ask user to input a positive integer n
$25