Here we will write a program to find sum of all the digits of an integer using looping
#include<stdio.h>
int main()
{
int n, sum=0, rem;
printf("Enter the no : ");
scanf("%d",&n);
while(n!=0)
{rem=n%10;
sum+=rem;
n/=10;
}
printf("Sum of digits = %d ",sum);
return 0;
}
No comments:
Post a Comment