5 Digit No. Enter by User Calculate the Sum Of It's Digits

How to write a c program if a Five digit number is input through the keyboard, write a program to calculate the sum of its digits in C Programming ?


Solution:
/*Five digit number is input through the keyboard, write a program to calculate the sum of its digits. */

#include <stdio.h>
 int main()
{

int i=0,j,a[5],sum=0;
printf("Enter the digits of the array");

for(j=0;j<5;j++)
{
scanf("%d",&a[j]);
}

while(i<5)
{

sum+=a[i];
i++;
}
printf("The sum of the digits of the array given is %d \n",sum);

return(0);
}


Learn More :