Write a program that prints all numbers from 1 to n

Assignment Help C/C++ Programming
Reference no: EM132107912

Programming C++

Exercise

Exercise 1. Use the for statement in a program that prints all the numbers from n1 to n2, where n1 and n2 are two numbers specified by the user.

(Hint: You'll need to prompt for the two values; then, inside the for statement, initialize i to n1, and use n2 in the loop condition.)

Exercise 2. Rewrite the example so that it prints all the numbers from n to 1 in reverse order. For example, the user enters 5, and the program prints 5 4 3 2 1.

(Hint: In the for loop, initialize i to n, use the condition i >= 1, and subtract 1 from i in the increment step.)

Exercise 3. Write a program that prints all numbers from 1 to n, but prints only even numbers or only odd numbers. Each number printed will be 2 higher than the last.

Reference no: EM132107912

Questions Cloud

What is the growth outlook : What is the Growth outlook and the Level of barriers to entry the Petroleum Industry?
Explain why german market is the better one : Management group believe German is better than England. List those two countries' advantage and disadvantage and explain why German market is the better one
Compute a factorial that can fit within an unsigned 16 bit : You will use your newfound looping knowledge to compute a factorial that can fit within an unsigned 16 bit integer.
What is the fair price of one afa bond to the nearest cent : Given the risk of AFA and its recent credit downgrade to CC, the required return on these bonds is now 17.5%.
Write a program that prints all numbers from 1 to n : Use the for statement in a program that prints all the numbers from n1 to n2, where n1 and n2 are two numbers specified by the user.
What is the current value of bank bills : If the current 180-day bill rate is 6.9% p.a., what is the current value of these bank bills to the nearest dollar?
Write a simulator in which one round of simulation involves : Write a simulator in which one round of simulation involves flipping a set of ten unfair coins in which there is a fixed likelihood.
Report the number of guesses made and terminate execution : Imagine that the user will write down a positive integer x on a piece of paper and your program will repeatedly ask questions in order to guess what x is.
Implement a recursive quicksort algorithm : For this lab, you will first populate an array with integer values provided by a user and then you will sort the array.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write c code to repeatedly ask the user for a number

Write C code to repeatedly ask the user for a number, then once the user enters 0, the code displays the min, max and average of all values entered.

  Manipulate c character strings which are simply arrays

In this exercise, you will manipulate C character strings, which are simply arrays of characters that are terminated by the ASCII NULL character (0x00, '\0').

  Prepare a program to find out the perfect numbers

Write a program in C++ that outputs all perfect numbers and their factors from 1 to 1000 using your own created function - Prepare a program to find out the perfect numbers and it must compile with no errors and follow the directions.

  Find the total number of lines in a collection

Write two functions, so that we can find the total number of lines in a collection of text files.

  Function that accepts a pointer to a string as an argument

Must actual count the number of words. User must be able to input a stringand then pass the string to the function. The function must also display the average number of letters in each word.

  Write a gui program in graphics class to draw a smiley face

Write a GUI program that uses the methods in the Graphics class to draw a smiley face when the window is activated, and a frowny face when the window.

  Write a program that asks the user for a profile name

Write a program that asks the user for a profile name and displays the number of characters, words, and lines in that file. Then have the program ask for the name of the next file. When the user enters a file that doesn't exist (such as the empty ..

  Encode the message using the code

Any way anyone could help me with this program? Read in a code -- one character for each of the letters of the alphbet.

  What is the output

What is the output - This one is complex and I don't know how to do it

  What is the output of the following statements

What is the output of the following statements? Suppose a and b are int variables, c is a double variable, and a = 13, b = 5, and c = 17.5.

  What are the advantages of using an ordered array

What are the inefficiencies associated with using an unordered array if duplicates are not allowed? What are the advantages of using an ordered array? When would using an unordered array be preferred over using an ordered array

  Problem on enhance the hash set class

Suppose you were asked to enhance the Hash Set class. Suggest one new method for that class that could be used to manipulate the data in a variety of ways.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd