write a write a program in which you can put four digit number and print each digit of the number in a separate line for example if a user has input 1234 as the four digit number then the output should be:
4
3
2
1
Answers
Answered by
0
Answer:
// C program to compute sum of digits in
// number.
# include<iostream>
using namespace std;
/* Function to get sum of digits */
class gfg
{
public:
int getSum(int n)
{
int sum = 0;
while (n != 0)
{
sum = sum + n % 10;
n = n/10;
}
return sum;
}
};
//driver code
int main()
{
gfg g;
int n = 687;
cout<< g.getSum(n);
return 0;
}
//This code is contributed by Soumik
C
Java
Python3
C#
PHP
Similar questions