Code is here:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
#include<stdio.h> int main() { int number; scanf("%d",&number); char digits[2000000]; int i=0,d; while(number>0) { d=number%10; digits[i]=d; //putting the values in char array //as we have put the int value so we are using %d //printf("%s",digits); number=number/10; //it is diving to get one digit number as we looping till zero (0) ++i; //pre incrementing the value of i } digits[i]='\0'; //char array last value is this // printf("%d\n",i); int t,sum=0; for(t=i-1; t>=0; t--) //we need i-1 as it is just before the null value of the array { printf("%d\t",digits[t]); //printing values from saved char array sum=sum+digits[t]; //summing all the values of this array } printf("\n Sum of all digits = %d",sum); return 0; } |

Output:

1 2 3 |
88567 8 8 5 6 7 Sum of all digits = 34 |

Modular Beautiful Code: 😀

Actually array return function is not directly possible in C and I am finding the solution here.

Took Slightly Help From this link:

https://cboard.cprogramming.com/c-programming/150996-extracting-digits-integer.html