0

hi ! I want to sum of digts on C++ but when get the nagative number give me the result if pastive number like when u write -98 answer u 17 not -17

#include<iostream>
#include<math.h>


using namespace std;


int main(){
    int N=0 ;
    cin>>N;
    int sum=0;
    while(N!=0){

            sum += (N%10);
        N = N / 10;
    }
    cout << sum << endl;


}
3
Contributors
3
Replies
23
Views
3 Years
Discussion Span
Last Post by Lerner
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.