KodeGod.com

030. Write a Program to accept a number and print sum of it’s digits in C language

#include<stdio.h>
#include<conio.h>  
main()
{
  int rem,sum=0,n
  clrscr();
  printf("Enter n : ");
  scanf("%d",&n);
  while(n>0)
  {
	   rem=n%10;
	   sum=sum+rem;
	   n=n/10;
  }
  printf("Sum of digits....%d",sum);
  getch();
}