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
What is microsoft certification?
BabaBlast [244]
Microsoft certification is a series of programs that provide certification of competence in Microsoft products.
6 0
2 years ago
1.Public policy begins with . 2.Then, government officials . 3.Finally, a government agency .
dexar [7]

Answer:

what was the wuestion

Explanation:

cause we dont know how to help you

4 0
3 years ago
Which feature of a blog helps to store and retrieve older posts?
Rashid [163]
Could it be archive posts? I'm not sure, but I believe it's archive posts.
8 0
3 years ago
Read 2 more answers
Asking questions when something is unclear is part of
Ksenya-84 [330]
Personally responsibility

Hope this helps
6 0
3 years ago
5 steps in cleaning and sanitizing smokehouse​
topjm [15]

Answer:

  1. Scrape or remove food bits from the surface.
  2. Wash the surface.
  3. Rinse the surface.
  4. Sanitize the surface.
  5. Allow the surface to air-dry.

Explanation: These are steps for cleaning and sanitizing.

4 0
3 years ago
Other questions:
  • Use the image below to answer this question.
    14·1 answer
  • All the computers in this type of network are connected to two other computers.
    12·1 answer
  • Does anybody know if that apple watch is actually worth what it costs?
    9·2 answers
  • Clicking the ____ opens the insert function dialog box.
    13·1 answer
  • Why might you want to save a downloaded file to your computer first instead of running it immediately?
    6·1 answer
  • Write if true or false
    12·1 answer
  • Im lonellly whos down to date me
    7·2 answers
  • Which is a linear presentation?
    10·1 answer
  • Immigrants are allowed to enter the country to work when they have a(n)
    10·1 answer
  • The equals method of the Object class returns true only if the two objects being compared:_________
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!