Pages

Saturday, December 3, 2011

C Programming to read four digit number and find the sum of all digits (easy way)


/* to read 4 digit no. and find their sum */
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int sum,n;
    sum+=n%10;
    n=n/10;
    sum+=n%10;
    n=n/10;
    sum+=n%10;
    n=n/10;
    sum+=n%10;
    printf("The sum of digits=%d",sum);
    system("pause");
    return 0;
}

No comments:

Post a Comment