Write a program to enter a number and display the sum of its digits. (using while loop)
Input : 642 Output : 12 (6+4+2 = 12)
Answers
Answered by
2
Answer:
#include<stdio.h>
#include<conio.h>
void main()
{
int sum=0,n,i;
printf("enter the numbers");
scanf("%d",&n);
while(n>0)
{
rem=n%10;
sum=sum+rem;
n=n/10;
}
printf("%d sum of digits is",sum);
getch();
}
Explanation:
Similar questions
Computer Science,
5 months ago
Physics,
5 months ago
Chemistry,
5 months ago
English,
10 months ago
Science,
1 year ago