Tuesday, March 5, 2024

26. Sum of digits :—

 26. Sum of digits :—


#include<stdio.h>

int main()

{

    int i,n,r,k,sum;

    printf("enter value of n ");

    scanf("%d",&n);

    sum=0,k=n;

    while(n>0)

    {

        r=n%10;

        n=n/10;

        sum=sum+r;

    }

    printf("%d",sum);

    return 0;

}


No comments:

Post a Comment