Wednesday, 11 February 2015

u1p4

Program to add the digits of given integer number.


 #include<iostream.h>  
 #include<conio.h>  
 void main()  
 {  
      clrscr();  
      int D,sum=0;  
      cout<<"This program will add the digits of given integer number(MAX 32767).\n";  
      cout<<"Enter integer value : ";  
      cin>>D;  
      while(D>0)  
      {  
            sum = sum + D%10;  
            D = D/10;  
      }  
      cout<<"\n\nSum of the digits of given integer is "<<sum;  
      getch();  
 }  

OUTPUT :


No comments:

Post a Comment