Sunday, 26 September 2021

WAP to print of digits of a entered number.

// WAP to print of digits of a entered number

#include <iostream>

#include<cstdlib>

using namespace std;


int main() {

    string str; 

    cout<<"Enter a number: "<<endl;

    cin>>str;

    int sum = 0;

    for (int i=0; i<str.length(); i++) {

        sum += str[i] - '0';

    }

    cout<<"Sum of all digit: "<<sum<<endl;

}


Popular Posts