| |
GeekInterview.com > Interview Questions > Programming
| Print | |
Question: Write a program to read a four digit integer and print the sum of its digits.
Write a program that reads a floating point number and then displays the right-most digit of the integral part of the number.
|
| April 04, 2008 04:57:31 |
#3 |
| gatadivaddavinod |
Member Since: April 2008 Total Comments: 2 |
RE: Write a program to read a four digit integer and print the sum of its digits.Write a program that reads a floating point number and then displays the right-most digit of the integral part of the number. |
#include<iostream.h> #include<conio.h>
void main() { clrscr(); int n,r,sum=0; cout<<"Enter any four digit number"; cin>>n; while(n>0) { r=n%10;//To get remainder sum=sum+r; n=n/10;//To get coefficient } cout<<"The sum of the given four digt number is:"<<sum; getch(); } |
| |
Back To Question | |