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
Naya [18.7K]
3 years ago
13

Read an integer number from the user. If the number is not positive, change its sign. Create the algorithms for the following ta

sks: 1 Count the digits of the number 2 Count the odd digits of the number 3 Calculate the sum of the digit values of the number
Computers and Technology
1 answer:
atroni [7]3 years ago
3 0

Answer:

ALGORITHM READ_NUMBER()

1.       SET NUM := 0 [INITIALLY SET THE VALUE OF NUM TO 0]

2.       WRITE : “Input a Number” [DISPLAY A MESSAGETO USER]

3. READ NUM [STORE THE VALUE TO NUM]

4.       IF NUM<0 [IF VALUE OF NUM IS -VE THEN MULTIPLY IT BY -1]

5.       NUM := NUM * (-1)

6.       [END OF IF]

7.       RETURN NUM [RETURN THE NUMBER]

1. ALGORITHM DIGIT_COUNT(NUM)

SET COUNT := 0

SET R:=0

REPEAT WHILE(NUM != 0)

R := NUM MOD 10

COUNT : = COUNT+1

NUM := NUM/10

[END OF LOOP]

RETURN COUNT

2. ALGORITHM DIGIT_ODDCOUNT(NUM)

SET COUNT := 0

SET R:=0

REPEAT WHILE(NUM != 0)

R := NUM MOD 10

IF (R MOD 2 != 0)

COUNT : = COUNT+1

[END OF IF]

NUM := NUM/10

[END OF LOOP]

RETURN COUNT

3. ALGORITHM SUM_OF_DIGITS(NUM)

SET SUM := 0

SET R:=0

REPEAT WHILE(NUM != 0)

R := NUM MOD 10

SUM : = SUM+R

NUM := NUM/10

[END OF LOOP]

RETURN SUM

C++ PROGRAM

#include<iostream>

using namespace std;

//method to count the number of digits

int digit_count(int num)

{

   int count=0; //set count to 0

   int r;

   //loop will continue till number !=0

   while(num!=0)

   {

      r=num%10; //find the individual digits

      count++; //increase the count

      num=num/10; //reduce the number

  }

  return count; //return the count

}

int odd_digit_count(int num)

{

   int count=0;//set count to 0

   int r;

   //loop will continue till number !=0

   while(num!=0)

   {

      r=num%10;//find the individual digits

      if(r%2!=0) //check for odd digits

      count++;//increase the count

      num=num/10;//reduce the number

  }

  return count;//return the count

}

int sum_of_digits(int num)

{

   int sum=0;

   int r;

   //loop will continue till number !=0

   while(num!=0)

   {

      r=num%10;//find the individual digits

      sum=sum+r;//find the sum of digits

      num=num/10;//reduce the number

  }

  return sum;//return sum

}

//input method

int input()

{

  int x;

  cout<<endl<<"Enter a number";

  cin>>x;//read the number

  if(x<0) //if -ve then turn it to +ve

  x=x*-1;

  return x; //return the number

}

//driver program

int main()

{

  int n,dc,odc,sod;

  n=input(); //call to input()

  dc=digit_count(n); //call to digit_count()

  odc=odd_digit_count(n); //call to odd_digit_count()

  sod=sum_of_digits(n);//call to sum_of_digits()

  //display the details

  cout<<endl<<"The positive number is : "<<n;

  cout<<endl<<"The number of digits in "<<n<<" is "<<dc;

  cout<<endl<<"The number of odd digits in "<<n<<" is "<<odc;

  cout<<endl<<"The sum of digits of "<<n<<" is "<<sod;

}

Explanation:

You might be interested in
Explain Software licensing
lbvjy [14]

Answer:

Software Licensing is pretty much allowing another company to use your own product.

Explanation:

<u>For Example:</u>

<u>Company A</u> is working on a face swap application which requires a facial recognition software in order to work. They can either build one from scratch (which can take months) or they can pay someone who already has one in order to be able to use it.

<u>Company B</u> owns a facial recognition software and are asked by Company A to license their software to them. Company A pays Company B, they then draft up a contract for Company A allowing them to use the facial recognition app.

Software licenses are either proprietary, free, or open source. Proprietary is the one used in the example above.

I hope this answered your question. If you have any more questions feel free to ask away at Brainly.

5 0
3 years ago
If you are creating a new document that you know will be turned into a Web page, it is a good idea to start in _____.
Lina20 [59]
I think you should start in Web layout
7 0
3 years ago
How to jailbreak ios 9.2 ? Is there anyway???!!!!
Leviafan [203]
Use Pangu 9.2 iOS jailbreak installer.
1. get the Pagnu 9.2 installer
2. connect your iOS 9.2 device to your Windows/OS X machine via universal serial bus cord
3. go through with the setup wizard
6 0
3 years ago
Which of these are steps in the testing cycle? Check all of the boxes that apply.
ollegr [7]

Answer:

A,C and D

Explanation: You're welcome

5 0
3 years ago
Read 2 more answers
What project started the development of inter-network connections using tcp/ip that has evolved in to the internet today
Vinvika [58]
The <span>ARPANET </span><span>project started the development of inter-network connections using TCP/IP that has evolved in to the internet today</span>
4 0
3 years ago
Other questions:
  • 1. What should you do if your computer is shared by your entire family and you install a plugin that saves user names and passwo
    5·2 answers
  • All java classes must contain a main method which is the first method executed when the java class is called upon.
    10·1 answer
  • Without a well-designed, accurate database, executives, managers, and others do not have access to the ____________________ they
    15·1 answer
  • Microsoft is interested in customers' perceptions of Windows 8, its new PC operating system. Since the research goal is rather s
    15·1 answer
  • When the amount of storage data is big, and we need the searching and insertion must be very fast, which kind of data structure
    9·1 answer
  • Hoda needs to create a chart that is associated with an Excel spreadsheet. She needs to ensure that if the data in the spreadshe
    12·1 answer
  • Help fast pleas. 3. How is this text formatted? (1 point)
    14·1 answer
  • Which shortcut keys can be used to duplicate a slide?
    15·1 answer
  • When running the following code:
    10·1 answer
  • (2 points) starting from the root node, we want to populate a bst with the keys in a given list without altering the key order.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!