Pages

Saturday, 20 June 2020

Sum of digit program C language

Q : Write a program to find the sum of the digits of a number.

Answer :


#include<stdio.h>
#include<conio.h>
/*##########################
     Girfa Student Help
     Sum of digits of a number
  ##########################*/
void main()
{
   
  int i,j;
     clrscr();
     printf("Enter number>> ");
     scanf("%d",&i);
     j=0;
     while(i>0)
     {
          j=j+(i%10);
          i=i/10;
     }
     printf("\n\tSum of digits is %d",j);
     getch();
}

No comments:

Post a Comment