C Program to find sum of digits of positive integer - c programs
//write a C Program to find sum of digits of positive integer
//print sum of digits of positive integer in / using c program
//C Program to print sum of digits of positive integer
#include<stdio.h>
#include<conio.h>
void 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();
}
No comments:
Post a Comment