Tuesday, March 5, 2024

15. Sum of digits :—

15. Sum of digits :—


#include<stdio.h>

int main()

{

    int r,n,sum;

    printf("enter a value of n ");

    scanf("%d",&n);

    sum=0;

    while(n>0)

    {

        r=n%10;

        sum=sum+r;

        n=n/10;

    }

    printf("%d",sum);

    return 0;

}


No comments:

Post a Comment