Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // funtions.cpp.cpp : This file contains the 'main' function. Program execution begins and ends there.
- //
- #include <iostream>
- using namespace std;
- int sum(int num)
- {
- int sum = 0;
- int num2 = 0;
- while (num > 0)
- {
- for (int i = 0; i < num; i++)
- {
- num2 = num % 10;
- sum = sum + num2;
- num = num / 10;
- }
- }
- return sum;
- }
- int main()
- {
- int num;
- cout << "Enter a number: \n";
- cin>>num;
- cout<<sum(num);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement