#include<string.h>
int main() {
int number1, number2;
char str[10];
printf("\nEnter a Number:::");
scanf("%d", &number1);
sprintf(str, "%d", number1);//step 1
strrev(str);//step 2
number2 = atoi(str);//step 3
printf("\n Reverse of the number:::");
printf("%d", &number2);
return 0;
}
OUTPUT:
Enter a Number ::: 1234
Reverse of the number::: 4321
Explaination of above code:-
Storing the number into Form of String:-
sprintf() function sends formatted "number1" to string variable "str".
Using strrev() function to reverse the string "str"
eg 1234 will be reversed as 4321
Convert String to Number using atio() function:
atoi() stands for "Alphabet to Integer". This function converts "String to Integer".
0 Comment(s)