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 the practice of distributing responsibility among multiple people so that no one person has full control of
Sholpan [36]

Answer:

If the responsibilities are distributed ,the disputes amongst people wont take place because their wont be any partiality, everyone would be equal. Moreover it is difficult for one person to control everything at once and multiple people would help the work to be organized as everyone will have their own part of work which is supposed to be fulfilled.

8 0
3 years ago
Nathan would like to save his PowerPoint presentation as a video that can be replayed easily on any device at full quality. Whic
valentina_108 [34]

Answer:

Presentation Quality

Explanation:

It will be full quality as it is from when your presenting

6 0
3 years ago
You’re responsible for an always-on VPN connection for your company and have been told that it must utilize the most secure mode
liq [111]

Answer:

Tunneling

Explanation:

A networking protocol that is used to send data from one network to another network by encapsulation process.

It is the more secured method as it secures the data with the help of encapsulation process. Rest of the protocols are not helpful in security of data.

8 0
3 years ago
Write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, a
Viktor [21]

Answer:

The program to this question can be given as:

Program:

import java.util.*;

//import package for user input  

class Main     //define class

{

public static void main(String a[])  

//define main function

{

int positive_number=0,negative_number=0,count=0,num; //define variable

double total=0,avg=0;  

//creating Scanner class object.

Scanner ob = new Scanner(System.in);

System.out.println("Enter an integer, when done input 0: "); //message

num= ob.nextInt();

//taking input from user

if (num==0)  //check number equal to 0  

{  

System.out.println("No numbers are entered except 0"); //message

System.exit(1);

}

else

{

while (num!= 0)  

{    

   if (num> 0)

   {

positive_number++; // Increase positives

}

else

{

negative_number++; // Increase negatives

}

total=total+num; // Accumulate total

count++;    // Increase the count

num=ob.nextInt();

}

// Calculate the average

avg=total/count;

// Display values

System.out.println("The positive number is:"+positive_number);

System.out.println("The negatives number is:"+negative_number);

System.out.println("total is:"+total);

System.out.println("average is:"+avg);

}

}

}

Output:

Enter an integer, when done input 0: 22

2

1

4

0

The positive number is:4

The negatives number is:0

total is:29.0

average is:7.25

Explanation:

In the above program firstly we import the package for user input then we define a class that is main in this class we define the main method in the main method we define variable. Then we create a scanner class object for user input. In the number variable, we take multiple inputs from the user and also check that the user does not insert 0 at the starting of the program. To check this we use the condition statement that is a number equal to 0 then it will terminate the program. In the else part we first declare the loop that checks that inserted number is positive and negative and in this, we calculate the total of the numbers and at the end of the loop, we calculate the average of the number and print all the values.

4 0
3 years ago
Read 2 more answers
Hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
uysha [10]

Answer:

hhhhhhhhhhh

hhhhhhhjjjhh

8 0
3 years ago
Read 2 more answers
Other questions:
  • Which of the following are common problems experienced with software applications?
    15·1 answer
  • four quantum numbers that could represent the last electron added (using the Aufbau principle) to the Argon atom. A n = 2, l =0,
    14·1 answer
  • HELP PLEASE
    5·1 answer
  • Create a program that generates a report that displays a list of students, classes they are enrolled in and the professor who te
    11·1 answer
  • This is pixlr
    6·1 answer
  • Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binar
    12·1 answer
  • What is the difference between - and % in mysql
    15·1 answer
  • If you copy a drawing from the Internet and use it in a report, you might be violating the artist's
    8·1 answer
  • Which statement best defines the Control Pannel?
    12·1 answer
  • Photographs, illustrations, and videos are increasingly created an and viewed in digital formats. True or False​
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!