C Program to print the Sum of the digits of all the Elements of an Array


 

// Program by Akash Tripathi (@proakash256) 
 
#include <stdio.h>
int sum(int *n)
{
    int  s = 0 , t = *n;
    while(t > 0)
    {
        s = s + (t % 10);
        t = t / 10;
    }
    return s;
}
int main()
{
    int n;
    printf("Enter the number of elements
            you want to enter : ");
    scanf("%d", &n);
    int ar[n];
    printf("\nEnter the Elements :\n");
    for (int i = 0i < ni = i + 1)
        scanf("%d", &ar[i]);
    printf("The Sum of the elements are :\n");
    for(int i = 0i < ni = i + 1)
    {
        int s = sum(&ar[i]);
        printf("%d\n" , s);
    }
    return 0;
}

Comments