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
Svetach [21]
3 years ago
3

Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum

of the digits. For example, it should output the individual digits of: 3456 as 3 4 5 6 8030 as 8 0 3 0 2345526 as 2 3 4 5 5 2 6 4000 as 4 0 0 0 -2345 as 2 3 4 5
Computers and Technology
1 answer:
LUCKY_DIMON [66]3 years ago
4 0

Answer:

The following program is written in C++ Programming Language:

#include <iostream>           //header file

using namespace std;        //using namespace

int main(int argc, char* argv[])     //set parameterized main() function

{

   int a=0,b[100]={0},n=0,sum=0;     //declare integer variables and array

   cin>>a;        //get number from the user

   while(a>0)     //set the while loop

   {

       b[n]=a%10;  

       a/=10;

       n++;

   }

   for(int i=n; i>0; i--)      //set the for loop

   {

       printf("%d ",b[i-1]);    

       sum+=b[i-1];

   }

   printf(" Sum: %d ",sum);       //print the result

   cin.get(); cin.get();

   return 0;

}

Input:

8030

Output:

8 0 3 0   sum: 11

Explanation:

Here, we define the header file "iostream" and the namespace "std"

then, we set the parameterized main() method.

Then, we set three integer variables "a" to 0, "n" to 0, "sum" to 0 and an integer array variable "b[100]" to {0}.

Then, we get a number from the user in variable "a".

Then, we set the while loop and pass the condition then, pass the for and pass the condition after that we print the result.

You might be interested in
What is the different between information and data
Scorpion4ik [409]

Answer:

Information is the act of imparting knowledge and data is the recorded observation that are usually presented in a structured format

6 0
3 years ago
Computer that process digital as well as analogue signals​
Nuetrik [128]

Answer:

The answer is hybrid computer coz it is the combination of both analog and digital computers

Explanation:

hope it helps

good day

5 0
3 years ago
When do we use an if- statement ​
wel

Answer:

You'd use an if statement if something happens. What I mean is that {If this happens} Then that happens but if the if doesnt happen then the then doesnt happen

Explanation:

3 0
3 years ago
Read 2 more answers
Favorite video games list atleast 5<br><br> favorite to least
Aneli [31]

Answer:

Rob lox, Sub nautica, Phasmo phobia, Albion Online,  fnf.

Explanation:

6 0
3 years ago
Write a java program to read elements in an array from user and count total number of duplicate elements in array.
Anna11 [10]

Answer:

Explanation:

The following code is written in Java and is a function/method that takes in an int array as a parameter. The type of array can be changed. The function then creates a counter and loops through each element in the array comparing each one, whenever one element is found to be a duplicate it increases the counter by 1 and moves on to the next element in the array. Finally, it prints out the number of duplicates.

public static int countDuplicate (int[] arr) {

               int count = 0;

               for(int i = 0; i < arr.length; i++) {

                       for(int j = i + 1; j < arr.length; j++) {

                               if(arr[i] == arr[j])

                                       count++;

                       }

               }

               return count;

       }

8 0
3 years ago
Other questions:
  • What type of organizational structure would you want to use for this company (by function, by process, by product, and so on)? E
    11·1 answer
  • Which hardware component is most suspect if a user can barely make out
    10·1 answer
  • In this lab, you will create a programmer-defined class and then use it in a Java program. The program should create two Rectang
    14·1 answer
  • Your organization recently deployed a Windows domain controller with Active Directory. All the domain OU users need to run the s
    11·1 answer
  • Stuart wants to delete some text from a slide. What should Stuart do?
    8·1 answer
  • Write a brief, two-page paper describing how your lifestyle and values impact your use of the Web for e-commerce. How is your on
    15·1 answer
  • What is the major difference between the intranet and extranet?
    11·1 answer
  • For what purposes do students collect data? Check all that apply.
    7·2 answers
  • Question # 7
    11·1 answer
  • Modify the program you wrote for Chapter 6 Exercise 6 so it handles the following
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!