Showing posts with label SUM OF DIGITS. Show all posts
Showing posts with label SUM OF DIGITS. Show all posts

Wednesday, January 28, 2015

SUM OF DIGITS


PROGRAM:

#include<stdio.h> int sum(int n,int s)

{

if(n<10) return n;

else

return (n%10)+sum(n/10,s);

}

main()
{

int n,s=0;


printf("\nEnter a Number\n");
scanf("%d",&n);
s=sum(n,s);

printf("\nThe sum of digits %d is %d\n",n,sum(n,s));
}



OUTPUT:

Enter a Number 46612

The sum of digits 46612 is 19

Thursday, January 15, 2015

SUM OF DIGITS

PROGRAM:

#include<stdio.h> main()
{
int n,i,sum=0;

printf("Enter a Number\n"); scanf("%d",&n);

do

{

i=n%10;

sum=sum+i;

n=n/10;

}while(n>0);

printf("The Sum of digit is %d\n",sum);

}


 OUTPUT:

Enter a Number 5891

The Sum of digit is 23