0
W.a.p enter a no. Find and display the sum of all digit of that no.
only for Loop , no, do and while
1 Respuesta
+ 1
Try using this:
#include<iostream>
using namespace std;
// declaring a function for your task
void task(int num){
int sum = 0, pro = 1;
while(num != 0){
dgt = (num%10);
num = int(num / 10);
sum += dgt;
pro *= dgt;
}
cout<<"Sum of digits: "<<sum;
cout<<"Product of digits: "<<pro;
}
int main(){
int n;
cout<<"Enter a number: ";
cin>>n;
// using the function with number
task(n);
return 0;
}