forked from sainirock61/CPP-Projects-Algos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsum of digits.cpp
More file actions
33 lines (23 loc) · 827 Bytes
/
sum of digits.cpp
File metadata and controls
33 lines (23 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<iostream>
using namespace std;
int main()
{
cout<<"\n\t\t\t\tPROGRAM TO PRINT THE SUM OF ALL THE DIGITS OF A NUMBER \n";
cout<<"\t\t\t====================================================================\n";
long int val , num , sum = 0;
cout<<"\n\t\t\t\tENTER THE NUMBER :-- ";
while(!(cin>>val)|| (val<=0))
{
cin.clear();
cin.ignore(100,'\n');
cout<<" !!!!! INVALID INPUT. ENTER AGAIN :-- ";
}
num = val ;
while(num !=0)
{
sum = sum + num%10;
num = num/10;
}
cout<<"\n\t\t\t\tTHE SUM OF THE DIGITS OF "<<val<<" is :- :"<<sum;
cout<<"\n\n\t\t\t====================================================================\n\n\n\n";
}