Pages

Friday 18 March 2011

PROGRAM TO CALCULATE THE SUM OF DIGIT OF NUMBER

DESCRIPTION-:THIS PROGRAM FINDS THE SUM OF THE DIGITS
OF THE ENTERED NUMBER.
FOR EXAMPLE IF WE HAVE NUMBER 123
THEN SUM=1+2+3=6.  
PROGRAM-:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,n,rem,sum=0;
cout<<"enter the value of n";
cin>>n;
while(n>0)
{
rem=n%10;
n=n/10;
sum=sum+rem;
}
cout<<"sum of digit is"<<sum;
getch();
}

0 comments:

Post a Comment

 
Copyright (c) 2010 Concepts Of C++. Design by WPThemes Expert

Blogger Templates and RegistryBooster.