Sunday, May 5, 2013

C program to find the sum of individual digits


/*Program to find the sum of individual digits*/
#include<stdio.h>
#include<conio.h>
main()
{
    int a,r,result;
    clrscr();
    printf("Enter A value:");
    scanf("%d",&a);
    r=result=0;
    while(a>0)
    {
        r=a%10;
        a=a/10;
        result=result+r;
    }
    printf("Sum of individual digits: %d",result);
    getch();
}

output:

Enter A value:125
Sum of individual digits: 8

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More