# C Program to find the sum of digits and reverse of a number with Algorithm

September 16, 2016

This is the C program code and algorithm for finding the sum of digits and reverse of a number.

**Aim:**

Write a C program to find the sum of digits and the reverse of a number.

**Algorithm:**

Step 1:StartStep 2:Read numbernumStep 3:Set sum=0 and rev=0Step 4:Repeat step 5 to 8 while numStep 5:Set d=num mod 10Step 6:Set num=num/10Step 7:Set sum=sum+dStep 8:Set rev=rev*10+dStep 9:Print sumStep 10:Print revStep 11:Stop

**Program code**

#include<stdio.h> #include<conio.h> void main( ) { clrscr( ) int num,sum=0,rev=0,d; printf("Enter the number: "); scanf("%d",&n); while(num){ d=num%10; num=num/10; sum=sum+d; rev=rev*10+d; } printf("Sumof digits = %d",sum); printf("\nReverse of the number = %d",rev); getch( ); }

**Output**

Enter the number : 123 Sum of digits = 6 Reverse of the number = 321