Reverse a Number in C Using Function

Reverse a Number in C Using Function for beginners to execute the program to reverse a number using a function in a c programming language.

Function Definition in C Program

A function is a collection of statements that work together to complete a task. 

Every C program has at least one function, main(), and even the simplest programs can define more functions. 

The name, return type, and parameters of a function are all specified in a function declaration. 

A function is a logical unit of code that is frequently defined by its place in a larger code structure. 

A function is a unit of code that works on a variety of inputs, many of which are variables, and produces concrete results such as changing variable values or performing actual operations based on the inputs.

While Loop in C

A while loop is a control flow statement in most computer programming languages that allows code to be executed repeatedly based on a given Boolean condition. 

The while loop is similar to a looping if statement. In C programming, a while loop executes a target statement repeatedly as long as a condition is true. 

A “While” Loop is used to repeat a block of code an unknown number of times until it meets a condition.

Reverse a Number in C Using Function

#include<stdio.h>
func(int n)
{
int sum=0;
while (n!=0)
{
sum = sum*10 + n%10;
n /= 10;
}
return sum;
}
int main()
{ 
int rev, num;
printf("Enter The Number");
scanf("%d", &num);
rev = func(num);
printf("The Reverse of Given Number %d is %d", num, rev);
}

Output:

Enter The Number4567
The Reverse of Given Number 4567 is 7654