C Program to Reverse the digits of a number in 3 Steps


C program to reverse the digits of a number ? [ In 3 Steps ]
Problem Statement : Reversing the digits of number without using mod (%) Operator ?

Prerequisite :

Output :

Explain Logic :
Step 1 : Store Number in the Form of String

  • Sprintf function sends formatted output to string variable specified
  • Number will be stored in String variable “str”

Step 2 : Reverse the String Using Strrev Function

  • Strrev will reverse String
  • eg “1234” will be reversed as “4321”

Step 3 : Convert String to Number

  • [A to I ] =  [ Alphabet to Integer ] = atoi
  • Atoi function Converts String to Integer