1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kap26 [50]
4 years ago
7

Given the number n as input, print the first n odd numbers starting from 1. For example if the input is 4 The ourput will be: 1

3 5 7
Computers and Technology
1 answer:
vivado [14]4 years ago
8 0

Answer:

The cpp program for the scenario is given below.

#include <iostream>

using namespace std;

int main() {

// number of odd numbers to be printed

int n;

// variable to keep count of odd numbers

int odd=1;

// variable to print odd numbers

int j=1;

// user is prompted to enter number of odd numbers to be displayed

cout<<"Enter the number of odd numbers to be printed ";

cin>>n;

do

{

// odd number is displayed

cout<<j<<" ";

// variable incremented after odd number is displayed

odd++;

// variable incremented to consecutive odd number

j = j+2;

// loop continues until required number of odd numbers are reached

}while(odd<=n);

}

OUTPUT

Enter the number of odd numbers to be printed 10

1 3 5 7 9 11 13 15 17 19  

Explanation:

The program works as described below.

1. The variable, odd, is declared and initialized to 1 to keep count of number of odd numbers to be displayed and other variable, j, declared and initialized to 1 to display odd numbers in addition to variable n.

2. User is prompted to enter value of n.

3. Inside do-while loop, initially, first odd number is displayed through variable j.

4. Next, variable odd is incremented by 1 to indicate number of odd numbers displayed.

5. Next, variable j is incremented by 2 to initialize itself to the next consecutive odd number.

6. In the while() clause, variable odd is compared against variable n.

7. The do-while loop executes till the value of variable odd becomes equal to the value of variable n.

8. The main() method has return type int and thus, ends with return statement.

9. The iostream is required to enable the use of basic keywords like cin and cout and other keywords.

10. This program can calculate and print any count of odd numbers as per the user.

You might be interested in
What is the ribbon used for in word
vitfil [10]

Answer:

the ribbon is a set of toolbar at a top of window in office program designed to help you quickly find a commans that you need to complete a task

Explanation:

what is the ribbon in word

6 0
3 years ago
I need ur oppinion about this paragraph.
choli [55]

I think that this answer is amazing and nothing really needs to be added. Well Done!

5 0
3 years ago
Read 2 more answers
What is the main difference between cloud computing and SaaS?
Artemon [7]

The answer is C: Cloud computing is a service, and SaaS is a platform.

Cloud computing and SaaS are closely related terms, but are different. Cloud computing consist of infrastructure and services and can be described as the delivery of computer services like, storage, databases, servers, and more over the internet. On the other hand, SaaS can refer to as a software delivery model licensed differently to on-premise applications and provide users with access to a vendor’s cloud based web applications or software.   


7 0
3 years ago
Which of the following is NOT an argument used to determine how a shot is fired from an A. object the shot itself being instanti
Firdavs [7]
C. The color of the shot...
7 0
3 years ago
Which of these devices is usually the default gateway for most home networks?
IrinaVladis [17]

What are the choices?

6 0
4 years ago
Other questions:
  • Most GUIs provide all of the following except _____.
    7·1 answer
  • Which resource do programmers sometimes have to refer to and use during planning the logical steps of the solution?
    10·2 answers
  • Computers store temporary Internet files in the Recycle Bin. These files take up space and slow down a computer. Which tool can
    10·1 answer
  • Write pseudocode instruction to carry out each of thefollowing computational operations.
    10·1 answer
  • Which button could Pamela press in the Microsoft Word spell checker to make the word “colour” instantly change to “color” whenev
    11·1 answer
  • The whole-part relationship created by object aggregation is more often called:___________.
    12·1 answer
  • Which of the following are screen objects used to maintain, view, and print data from a database
    9·1 answer
  • As you will solve more complex problems, you will find that searching for values in arrays becomes a crucial operation. In this
    9·1 answer
  • how does the use of data abstraction manage complexity in program code? how does using lists make a program easier to develop an
    5·1 answer
  • Algorithm to calculate the sum and difference of 15 and 12​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!