Showing posts with label Digits. Show all posts
Showing posts with label Digits. Show all posts

C++ Program to display a number's digits reversed.

C++ Program to display a number's digits reversed.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;
cout<<"Enter a number to display it's digits reversed: ";
cin>>a;
a=(a%10)*(10)+(a/10);
cout<<"The reversed number is: "<<a;
getch();
}

C++ Program to display the sum of a number's digits.

C++ Program to display the sum of a number's digits.



#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
cout<<"Enter a number to display sum of it's digits: ";
cin>>a;
b=a%10;
while(a!=0)
{
a=a/10;
c=a%10;
b=b+c;
}
cout<<"The sum of the digits is: "<<b;
getch();
}