Pages

Wednesday, November 30, 2011

C Programming to read four digit number and find the sum of all digits.


/* to read 4 digit number and find sum of all digits */
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n,n1,n2,n3,n4,S;
    printf("Enter the four digit number: ");
    scanf("%d",&n);
    n1=n%10;
    n2=(n/10)%10;
    n3=(n/100)%10;
    n4=(n/1000)%10;
    S=n1+n2+n3+n4;
    printf("The sum of numbers=%d",S);
    system("pause");
    return 0;
}

No comments:

Post a Comment