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
Nezavi [6.7K]
3 years ago
12

8.10 LAB: Convert to binary - functions Write a program that takes in a positive integer as input, and outputs a string of 1's a

nd 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x
Computers and Technology
1 answer:
Korvikt [17]3 years ago
3 0

Answer:

// This program is written in C++ programming language

// Comments are used for explanatory purpose

// Program starts here

#include <iostream>

#include <string>

using namespace std;

// Declare variables

int inputvar;

// Declare output variable as array

int outputvar[32];

// Set a counter for binary array

int i = 0;

while (inputvar > 0) {

// Divide inputvar by 2 and store remainder in outputvar

outputvar[i] = n % 2;

inputvar/=2;

i++; // increment i by 1

}

// End of division

// Prin resulting array in reverse order

for (int j = i - 1; j >= 0; j--) {

cout << outputvar[j];

}

return 0;

}

// End of Program

You might be interested in
____ are the in-house equivalent of Internet newsgroups. They use Web- or software-based discussion tools that are available acr
antiseptic1488 [7]
<span>The correct answer is Intranet chat rooms</span>
8 0
2 years ago
Which of the following activities can cause data to be damaged or lost?
jekas [21]
Illegal access to a system
3 0
3 years ago
write a 2d array c program that can capture marks of 15 students and display the maximum mark, the sum and average​
bekas [8.4K]

Answer:

#include <stdio.h>  

int MaxMark(int* arr, int size) {

   int maxMark = 0;

   if (size > 0) {

       maxMark = arr[0];

   }

   for (int i = 0; i < size; i++) {

       if (arr[i] > maxMark) {

           maxMark = arr[i];

       }

   }

   return maxMark;

}

int SumMarks(int* arr, int size) {

   int sum = 0;

   for (int i = 0; i < size; i++) {

       sum += arr[i];

   }

   return sum;

}

float AvgMark(int* arr, int size) {

   int sum = SumMarks(arr, size);

   return (float)sum / size;

}

int main()

{

   int student0[] = { 7, 5, 6, 9 };

   int student1[] = { 3, 7, 7 };

   int student2[] = { 2, 8, 6, 1, 6 };

   int* marks[] = { student0, student1, student2 };

   int nrMarks[] = { 4, 3, 5 };

   int nrStudents = sizeof(marks) / sizeof(marks[0]);

   for (int student = 0; student < nrStudents; student++) {              

       printf("Student %d: max=%d, sum=%d, avg=%.1f\n",  

           student,

           MaxMark(marks[student], nrMarks[student]),

           SumMarks(marks[student], nrMarks[student]),

           AvgMark(marks[student], nrMarks[student]));

   }

   return 0;

}

Explanation:

Here is an example using a jagged array. Extend it to 15 students yourself. One weak spot is counting the number of marks, you have to keep it in sync with the array size. This is always a problem in C and would better be solved with a more dynamic data structure.

If you need the marks to be float, you can change the types.

3 0
2 years ago
In which order does the processor search computer memory when it requires instruction or data?
skelet666 [1.2K]

Answer:

I think the answer is

Ram- Cache Memory-Hard disk

Explanation:

I hope this helps you

4 0
2 years ago
Bloodborne pathogens travel by way of blood cells and can only be spread by person-to-person contact with infected blood
Eva8 [605]
That is incorrect. It is only contagious if blood is injected into person who is not infected.
5 0
2 years ago
Read 2 more answers
Other questions:
  • Consider the following method: public static void arrayMystery(int[] array) { for (int i = 0; i &lt; array.length - 1; i++) { if
    10·1 answer
  • A cloud file system (CFS) allows users or applications to directly manipulate files that reside on the cloud.
    6·1 answer
  • Application software definition word excel powerpoint microsoft
    13·1 answer
  • What is the disadvantages of using proprietary software
    10·2 answers
  • What is online school like 6 sentences
    12·1 answer
  • The function below takes two numeric parameters. The first parameter specifies the number of hours a person worked and the secon
    13·1 answer
  • In java please
    13·1 answer
  • How are search results organized?
    6·1 answer
  • Simple Java programming
    15·2 answers
  • Question 1
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!