Reverse a Number in C Using For Loop

Reverse a number in c using for loop. In this program, we can execute the program to reverse a number using for loop.

For Loop in C Definition

A for loop is a repetition control structure that lets you write a loop that needs to run a certain number of times quickly. 

In the C programming language, the for loop is used to iterate statements or parts of a program several times. It is commonly used to traverse data structures such as an array and a linked list. 

A for-loop is a control flow statement in computer science that specifies iteration and allows code to be executed repeatedly. 

When the number of iterations is known before entering the loop, for-loops are commonly used.

Return Statement in C

A return statement marks the end of a function’s execution and hands control back to the calling function. 

The calling function resumes execution at the point where the call was made. 

A return statement can give the calling function a value.

Reverse a Number in C Using For Loop

#include <stdio.h>
int main()
{
int num,rem,rev=0;
printf("Enter The Number\n");
scanf("%d",&num);
printf("You Entered %d\n",num);
for(;num!=0; num=num/10)
{
rem=num%10;
rev=rev*10+rem;
}
printf("After reverse Number %d",rev);
return 0;
}

Output:

Enter The Number
456
You Entered 456
After reverse Number 654