#include #include int sumofdigits(int n); int main() { int num,sum,max_sum=0,max_num=0; // asking the user to enter a number before the loop printf("enter number or -1 to stop\n"); scanf("%d",&num); while(num!=-1) { sum=sumofdigits(num); //finding the maximum sum of the digits if(sum>max_sum) { max_sum=sum; max_num=num; } printf("enter number or -1 to stop\n"); scanf("%d",&num); } // the final result printf("the number with the largest sum of digits is %d",max_num); return 0; } int sumofdigits(int n) { int dig; int sum=0; while(n!=0) { dig=n%10; n=n/10; sum+=dig; } return sum; }