From 118e7f48cfe064ebe4c5a4b63088a0f95d4c11c6 Mon Sep 17 00:00:00 2001 From: Monalika Date: Wed, 26 May 2021 16:42:03 +0530 Subject: [PATCH] Create Code to find Sum of Digits of a Number using while loop.cpp --- ...of Digits of a Number using while loop.cpp | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Code to find Sum of Digits of a Number using while loop.cpp diff --git a/Code to find Sum of Digits of a Number using while loop.cpp b/Code to find Sum of Digits of a Number using while loop.cpp new file mode 100644 index 0000000..fe8dce0 --- /dev/null +++ b/Code to find Sum of Digits of a Number using while loop.cpp @@ -0,0 +1,26 @@ +/* C++ Program to find Sum of Digits of a Number using while loop */ + +#include +using namespace std; + +int main() +{ + long int a,num,no,sum=0; + + //----Enter any number which u want -------- + cout<<"Enter any integer :: "; + cin>>num; + + no=num; + + while(no>0) + { + a=no%10; + no=no/10; + sum=sum+a; + } + + cout<<"\nSum of Digits of a Number [ "<