// C program to compute sum of digits in
// number.
#include <stdio.h>
/* Function to get sum of digits */
int getSum(int n)
{
int sum = 0;
while (n != 0) {
sum = sum + n % 10;
n = n / 10;
}
return sum;
}
// Driver code
int main()
{
int n = 687;
printf(" %d ", getSum(n));
return 0;
}
#include <stdio.h>
int main() {
int number;
int sum=0,reminder;
printf("enter the number:");
scanf("%d",&number);
while (number>0){
rem=number%10;
sum=sum+rem;
number = number/10;
}
printf("%d",sum);
}
#include<stdio.h>
int main()
{
int a,b;
printf("enter numbers:");
scanf("%d %d",&a,&b);
printf("sum is:%d",(a+b));
}
#include <stdio.h>
void main (){
int i = 0 , s =0 ;
while (i<=10){
s = s + i ;
i++ ;
}
}
Enter the number
300
Given number = 300
Sum of the digits 300 = 3
Enter the number
16789
Given number = 16789
Sum of the digits 16789 = 31