If a five digit number is input through the keyboard .Write a program to calculate the sum of its digits.

Posted: September 23, 2012 in CSE Sem1, ECE Sem1, Lab 11A, Lab 11A
#include<stdio.h>
int main()
{
    int d1,d2,d3,d4,d5,sum;
    long num;
    printf("Enter a five digit number: ");
    scanf("%ld",&num);
    d1=(num%10);
    d2=(num%100)/10;
    d3=(num%1000)/100;
    d4=(num%10000)/1000;
    d5=(num/1000);
    sum=d1+d2+d3+d4+d5;
    printf("\n The sum of the digis is: %d",sum);
	return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s