how to write code to reverse given number in c program using function with comments
#include<stdio.h> //including header files
#include<conio.h>
long int reverse(long int); // declaring function with parameter
void main() // start main
{
long int n;
clrscr();
printf("enter the value \n"); // asking for enter the value
scanf("%ld",&n); // taking value from user
printf("result=%ld",reverse(n)); //calling function
getch();
}
long int reverse(long int a) // intialization of function
{
int r;
long int s=0;
while (a != 0) // checking number will not zero
{
r=a%10;
s=10*(s+r);
a=a/10;
reverse(a); // reversing number
}
return (s/10); //returning reversed number
}
c programming example for reverse number using function with while loop
0 comments: