Friday, 4 December 2015

SUM OF DIGITS

AIM
To write a C program to find the sum of digits of a given number.
ALGORITHM
Step 1: Start
Step 2: Read num
Step 3: rß(num%10)
            numß(num/10)
            sumß(sum+r)
Step 4: if (num>0) go to step 3
Step 5: Print sum
Step 6: Stop
PROGRAM
#include<conio.h>
void main()
{
    int num,r,s=0;
    printf("Enter the number\n");
    scanf("%d",&num);
    while(num>0)
    {
    r=num%10;
    s=s+r,num=num/10;
    }
    printf("Sum of digits = %d",s);

}

No comments:

Post a Comment