Tuesday 7 August 2012

Loop control structure011


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

#include <stdio.h>
#include <conio.h>

void main ( )
{
        int        md, no, s = 0;
        clrscr ( );
                 
        printf ("\n\t Enter a five digit number (less than 32767)......:"); scanf ("%d",&no);
             
        while ( no > 0 )
        {                     
                       md = no % 10;
                       no = no / 10;
                       s = s + md;
        }         
        printf ("\n\t SUM = %d",s);
        getch ( );
}

Click here to contact us

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...