Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that prompts the user to input an integer and then outputs both

ID: 3812805 • Letter: W

Question

Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits. For example, the program should: ouput the individual digits of 3456 as 3 4 5 6 and the sum as 18, output the individual digits of 8030 as 8 0 3 0 and the sum as 11, output the individual digits of 2345526 as 2 3 4 5 5 2 6 and the sum as 27, output the individual digits of 4000 as 4 0 0 0 and the sum as 4, and output the individual digits of -2345 as 2 3 4 5 and the sum as 14. but i need to use string and it should have 6 variables and 16 lines. i should use character.get Numeric value.

Explanation / Answer

/*Program using without character.get numeric function*/

#include <stdio.h>

int main(void){

int ans;

printf("enter an integer");

scanf("%d",&ans);

int x = ans;

size_t i, size = 0;

while ( x ) {

x=x/10;

size++;

}

int arr_answer[size],sum=0;

for ( i = size - 1, x = ans ; x ; x = x/10, i-- ) {

arr_answer[i] = x % 10;

}

for ( i=0 ; i < size ; i++ )

sum=sum+arr_answer[i];

{

for ( i=0 ; i < size ; i++ )

printf("%d ", arr_answer[i]);

}

printf(" Sum=%d", sum);

}

for using the character.getnumericvalue() the program need to be written in java and java.lang need to be used at the begin of program

the logic is as follows