Sum of Digits of an integer

Please tell me what is wrong , when i run it on code-chef IDE it shows run-time error.
But on the compilers online it does not show any error.
If anyone knows the answer please inform me about it .
Thank you :slight_smile:

//program to find sum of digits of an integer
#include <stdio.h>
#include<stdlib.h>

int main(void) {
// your code goes here

int limit,rem;
int myArr[limit];


//prompt user to input number of inputs

//printf("Enter limit: ");

scanf("%d",&limit);


//taking elements of array
for(int i=0;i<limit;i++)
{
    //printf("enter a number : ");
    scanf("%d",&myArr[i]);
    
}


for(int i=0;i<limit;i++)
{
    int sum=0;
    while(myArr[i]>0)
    {
     rem=myArr[i]%10;
     myArr[i]=myArr[i]/10;
     sum=sum+rem;  
    }
 printf("%d\n",sum);
    
}
return 0;

}

You are not giving a value to the limit variable and making an array size using that variable .
It will run with just a small change in your program

//program to find sum of digits of an integer
#include <stdio.h>
#include<stdlib.h>

int main(void) {
// your code goes here

int limit,rem;
//int myArr[limit];

//prompt user to input number of inputs
//printf("Enter limit: ");

scanf("%d",&limit);
int myArr[limit];

//taking elements of array
for(int i=0;i<limit;i++)
{
//printf(β€œenter a number : β€œ);
scanf(”%d”,&myArr[i]);

}

for(int i=0;i<limit;i++)
{
int sum=0;
while(myArr[i]>0)
{
rem=myArr[i]%10;
myArr[i]=myArr[i]/10;
sum=sum+rem;
}
printf("%d\n",sum);

}
return 0;
}