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
g The reciprocal Fibonacci constant ψ is defined by the infinite sum: ψ=∑n=1 [infinity] 1 Fn Where Fn are the Fibonacci numbers
timama [110]

Answer:

see explaination

Explanation:

MATLAB script:

% MATLAB script that calculates reciprocal Fibonacci constant Ψ

% Initial Values

a0 = 1;

a1 = 1;

% Looping variable

i = 2;

% Reading n value from user

n = input(' Enter n value: ');

% Initializing sum

sum = (1/a0) + (1/a1);

% Loop till i reaches n value

while i <= n

% Finding term in Fibnocii series

a2 = a0 + a1;

% Accumulating Sum

sum = sum + (1/a2);

% Updating previous terms

a0 = a1;

a1 = a2;

% Incrementing loop variable

i = i + 1;

endwhile

% Printing result

printf("\n Reciprocol Fibnocii Constant: %f \n", sum);

See attachment for sample output

5 0
3 years ago
You are a software engineer at a company where management routinely encourages you and your colleagues to use pirated software.
s2008m [1.1K]

Answer:

That’s highly illegal. You should notify them that it is illegal. And, if they continue, you should notify the legal team. If it continues, you either need to leave the company or notify the proper authorities.

7 0
2 years ago
In ip address 202.54.15.178, 15.178 is ______ address.
Tpy6a [65]

Answer:

Network address--An IP address with a host portion that is all zeros. Octet--An 8-bit number, 4 of which comprise a 32-bit IP address. They have a range of 00000000-11111111 that correspond to the decimal values 0-255. Packet--A unit of data passed over a TCP/IP network or wide area network.

7 0
2 years ago
A cycle merchant allows 15% discount on the marked price of a bicycle and still he makes a profit
lions [1.4K]

Answer:

The program in Java is as follows:

public class Main{

public static void main(String[] args) {

 double discount_percent = 0.15;

 double discount_amount = 600;

 double profit = 0.20;

 double marked_price = discount_amount/discount_percent;

 double cost_price = marked_price/(1 + profit);

 System.out.println("Marked Price: "+marked_price);

 System.out.println("Cost Price: "+cost_price);

}}

Explanation:

For explanation purpose, let

MP \to Marked Price

\%D \to Percentage discount

D \to Discounted amount

\%P \to Percentage Profit

C \to Cost Price

The marked price (i.e. selling price) is calculated discount using:

MP = \frac{D}{\%D}

The derived formula of the cost price from percentage profit and Marked Price is:

C = \frac{M}{1 + \%P * 100}

So, the explanation is as follows:

The next three lines declare and initialize the given parameters

<em>  double discount_percent = 0.15;</em>

<em>  double discount_amount = 600;</em>

<em>  double profit = 0.20;</em>

Calculate marked price

 double marked_price = discount_amount/discount_percent;

Calculate cost price

 double cost_price = marked_price/(1 + profit);

Print marked price

 System.out.println("Marked Price: "+marked_price);

Print Cost price

 System.out.println("Cost Price: "+cost_price);

3 0
2 years ago
The process of learning by making mistakes and by trial and error is called _____.
vodomira [7]
I believe it’s problem solving.
6 0
2 years ago
Other questions:
  • Use your own words to describe how IT/IS can support major functional areas in the business. Discuss at least two of these areas
    14·1 answer
  • Which of the following is a collection of honeypots used to present an attacker aneven more realistic attack environment?a. Padd
    6·1 answer
  • Rachel uses a word processor to write short stories. However, most of her time is spent toying with the keys, rather than in wri
    13·2 answers
  • 4
    10·1 answer
  • A very simple device that connects network components and sends packets of data to all other connected devices is called a _____
    5·1 answer
  • Which statement most aptly defines the term networking?
    8·1 answer
  • You have imported a library with the birthMonth() function. Based on the API, how many strings are inputed to calculate the birt
    11·1 answer
  • What is a document you can create with word-processing software
    9·1 answer
  • How to give a brainiest on a question? if you teach me i will give brainiest
    7·2 answers
  • Uh can somebody help me
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!