# Beginner to C.

 Milburn camilo · September 9, 2015 I am a beginer to C programing. When i run the below program it is giving error.Sum of individual digitsWrite a C program to find the sum of individual digits of a positiveinteger.Objective: The objective of this exercise is to find the sum of individualdigits of a positive integer.Program Code:#include#includevoid main(){int num, k=1, sum=0;clrscr();printf("Enter the number whose digits are to be added:");scanf("%d",&num);while(num!=0){k=num%10;sum=sum+k;k=num/10;num=k;}printf("Sum of the digits : %d", sum);getch();}Expected Output:Enter the number whose digits are to be added2 3Output5

## Replies

 Dara Shorten · September 9, 2015 Change int to float, int only deals with whole numbers that's why you don't get 2.3. int can only deal with numbers like 1 2 3 can't deal with 1.2 or in your case 2.3 Jon Z. · September 10, 2015 change void to int and make it return 0 at the end. that's the standard practice.``int main(){ //... return 0;}`` Sandra T · September 10, 2015 #include #include int main(){int num, k=1, sum=0;printf("Enter the number whose digits are to be added:");scanf("%d",&num);while(num!=0){k=num%10;sum=sum+k;num=num/10;}printf("Sum of the digits : %d", sum);return 0;}MAKE THE CHANGES THAT I'VE MADE AND YOUR PROGRAM WILL WORK! Milburn camilo · September 30, 2015 Thank you all.
• 1

## C

129,686 followers