Subscribe

RSS Feed (xml)

Monday, March 8, 2010

Write a C program that prints a given positive integer in reverse order and also sum of the individual digits involved in the given integer.

#include< stdio.h>
#include< conio.h>
int main( )
{
int no, rev=0, rem, sum=0;
clrscr( );
printf("Enter the required integer:");
scanf("%d", &no);
while(no>0)
{
rem = no%10;
rev = (10*rev)+rem;
sum = sum+rem;
no=no/10;
}
printf("\nReverse Number : %d", rev);
printf("\nSum of the individual digits : %d", sum);
getch( );

return 0;
}

Note: If any compile errors, please mail to me..

2 comments: