Code Scrappers


Add Digits of the Number Using Single Statement C program


              #include<stdio.h>
              #include<stdlib.h>

              void main()
              {
                  int n, sum = 0;

                  printf("Enter the number\n");

                  scanf("%d",&n);

                  for (; n > 0; sum = sum + n % 10, n = n / 10);

                  printf("\nSum of the Digits : %d", sum);
              }


          



Output

    Enter the number

    436

    Sum of the Digits : 13