Sum of digit of an integer
Problem Statement
Write a c Program to find out sum of digit of an integer by iterative method
#include<stdio.h>
int main() {
int n,sum,x;
printf("enter the number \n");
scanf("%d",&n);
sum=0;
while(n>=1) {
x=n%10;
sum=sum+x;
n=n/10;
}
printf ("the sum of digits is %d\n",sum);
return 0;
}
No comments:
Post a Comment