C program to reverse the given number.|Without function | Using Function|

Question: Write a programm in C to reverse the given number.

Source Code:

#include <stdio.h> int main() { int num,sum=0,rem; printf("Enter num \n"); scanf("%d",&num); while(num !=0) { rem=num%10; sum=(sum*10)+rem; num=num/10; } printf("Reverse of number: %d\n",sum); return 0; }

Output:

Enter num 345 Reverse of number: 543

Using Function:

#include <stdio.h> void reverse(int num) { int sum=0,rem; while(num !=0) { rem=num%10; sum=(sum*10)+rem; num=num/10; } printf("Reverse of number: %d\n",sum); } int main() { int num1; printf("Enter num1 \n"); scanf("%d",&num1); reverse(num1); return 0; }

Output:

Enter num 789 Reverse of number: 987

Comments

Popular posts from this blog

Introduction to Python.

Decision Making Statement.