I have to do a code for school which counts sum of digits. As it has to be working with big numbers (80 000 digits+) I had to do first count as an array as it was impossible to put this big number even in long long int. My question is why is this code not working? (works with smaller numbers for example: 10^100) but when I try really big numbers (10^10000) it does not work properly. Could anyone help me out by saying how or help me fix this? Thanks
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char pole [100000];
int c = 0;
int sum = 0;
int x = 0;
int t;
printf("Nacitaj cislo!\n");
scanf("%s", pole);
printf("Zadal si: %s\n", pole);
while (pole[c] != '\0') {
t = pole[c] - '0';
sum = sum + t;
c++;
}
while(1){
while(sum != 0){
x = x + sum % 10;
sum = sum/10;
}
if(x > 10){
sum = x;
}
else{
break;
}
}
printf("%d\n", x);
return 0;
}