Program to print sum of digits of the Integer

//Program to print sum of digits of the Integer
#include<stdio.h>
#include<conio.h>
int main()
{
  int n,rem,ans=0;
  clrscr();
  printf("Enter the number\n");
  scanf("%d",&n);
  while(n!=0)
  {
   rem=n%10;
   ans=ans+rem;
   n=n/10;
  }
  printf("The sum of digits is = %d",ans);
  getch();
  return 0;
}


To Run this Program Copy it in text editor and save as .c
Then double click on it and then it will get opened in your compiler.
Click on run.

No comments:

Post a Comment