Sum of Digit Using Goto Statement C Program



#include <stdio.h>


int main()
{
    int n, sum=0, r; 
    printf("\nEnter the number : ");
    scanf("%d" , &n);
    s:
    r=n%10;
    n=n/10;
    sum=sum+r;
    if(n!=0)
    {
        goto s; (will go to s and run again)
    }
    printf("\nSum = %d", sum);

    return 0;
}

Comments