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
Step-by-step 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.