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
lina2011 [118]
3 years ago
6

Write a program which increments from 0 to 20 and display results in Decimal on the console 2-b) Modify above program to increme

nt from 0 to 20 and display results in Binary on the console
Computers and Technology
1 answer:
SVEN [57.7K]3 years ago
3 0

Answer:

<em>This program is written in C++</em>

<em>Comment are used to explain difficult lines</em>

<em>The first program that prints 0 to 20 (in decimal) starts here</em>

#include<iostream>

int main()

{

//Print From 0 to 20

for(int i = 0;i<21;i++)

{

 std::cout<<i<<'\n';

}

}

<em>The modified program to print 0 to 20 in hexadecimal starts here</em>

#include<iostream>

using namespace std;

int main()

{

//Declare variables to use in conversion;

int tempvar, i=1,remain;

//Declare a char array of length 50 to hold result

char result[50];

//Print 0

cout<<"0"<<endl;

// Iterate from 1 to 20

for(int digit = 1; digit<21; digit++)

{

//Start Conversion Process

//Initialize tempvar to digit (1 to 20)

tempvar = digit;

while(tempvar!=0)

{

//Divide tempvar by 16 and get remainder

remain = tempvar%16;

if(remain<10)

{

 result[i++]=remain + 48;

}

else

{

 result[i++] = remain + 55;

}

//Get new value of tempvar by dividing it by 16

tempvar/=16;

}

//Print result

for(int l=i-1;l>0;l--)

{

cout<<result[l];

}

i=1;

cout<<endl;  

}

return 0;

}

//The Program Ends Here

See Attachments for program 1 and 2; program 2 is the modified version of 1

Download cpp
<span class="sg-text sg-text--link sg-text--bold sg-text--link-disabled sg-text--blue-dark"> cpp </span>
<span class="sg-text sg-text--link sg-text--bold sg-text--link-disabled sg-text--blue-dark"> cpp </span>
You might be interested in
The ________ is(are) used to display information on the computer's screen.
Novay_Z [31]

Answer:

cout object

Explanation:

Cout object -

This object is used while writing the program in the C++ , C , coding , the main function of Cout , is to display any information of the screen , is referred to as Cout object .

For example -

Cout<<"Hello";

From the above coding ,

The output would be -

Hello

The information to be displayed need to be written with double commas ( " " ).

5 0
3 years ago
Which are the best examples of costs that should be considered when creating a project budget?
Vlada [557]

Answer:

I would say material costs and hiring costs, idk if that helps or not

4 0
3 years ago
The ________ is an area where you can position fields to use for filtering the PivotTable and thereby enabling you to display a
Studentka2010 [4]

Answer: FILTERS area

Explanation: PivotTable is the kind of a tool that is used for the calculation of the data by analyzing ,summarizing ,comparing it according to the pattern and the sequence of the data.In this this tool. filter is used as the component for the filtering of the data in small/minor unit by analyzing it deeply. Different filter techniques is used in analyzing of the spreadsheet in PivotTable.

3 0
3 years ago
Which rotation speed is not a typical spindle rotation speed for magnetic hard drives?3100; 5400; 7200; 10000
Hitman42 [59]

Answer:

5,400 because it turns at the right speed, but if it is too fast or too slow, it will not perform at it's fullest potential. Such as speed and storage.

3 0
3 years ago
True false) ther are five arrow keys on the keborad​
cluponka [151]

Answer:

false, there's only 4

Explanation:

5 0
3 years ago
Other questions:
  • Write a function, factors, that takes an integer n, and returns a list of values that are the positive divisors of n. Note: 0 is
    13·1 answer
  • The main characteristic of ____ is that its source code is published with the software.
    7·1 answer
  • Describe an ergonomic consideration for your body while working for long periods in front of a monitor or computer screen?
    14·1 answer
  • It is always better to run over and give more information when you are giving a presentation versus quitting on time.
    11·2 answers
  • If there is a slow internet connection or limited access to certain sites it is often better to _________ a video file before st
    9·2 answers
  • What is the root of the tree?
    6·1 answer
  • How was WiFi discovered?
    8·1 answer
  • Which of the following technologies is an example of social media
    12·1 answer
  • Write a program to prompt the user for hours worked to compute a gross pay for an employee, and he is paid 100/hour. If he worke
    7·1 answer
  • RTOS stands for ______ Time Operating System.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!