write a program to swap the alternate digits of the given number from right to left

+2 votes
asked Jun 21, 2019 by anonymous
it should use only loops and decision making

2 Answers

0 votes
answered Jun 22, 2019 by sssr
main()

{

int no,rem,rev=0;

printf("enter a no");

scanf("%d",&no);

while(no!=0)

{

     no=no/10;

    rem=no%10;

   rev=rev*10+rem;

}

printf("%d is reverse no");

}
0 votes
answered Jun 22, 2019 by bekulio (180 points)
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <stdio.h>

unsigned int foo (unsigned int num);

int
main ()
{
  printf ("Hello World");

  printf ("\n reverse = %d", foo (556677));

  return 0;
}

unsigned int
foo (unsigned int num)
{
  unsigned int ret_num = 0, temp;

  while (num / 10 != 0)
    {
      ret_num += (num % 10);
      num /= 10;
      ret_num *= 10;

    }

  ret_num += num;

  return ret_num;
}
commented Jun 26, 2019 by meraj
main()
{
int x,r,s=0;
printf("enter a number");
scanf("%d",&x):
while(x!=0)
{
x=x/10;
r=x%10;
s=s*10+r;
}
printf("%d",s);
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...