Question: Write a programm in C to reverse the given number.
#include
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
#include
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
Post a Comment