Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

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

3 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);
}
0 votes
answered Jun 17, 2023 by viswanath (140 points)

#include <stdio.h>

#include <conio.h>

#include <string.h>

void main(){

    char str[20],tmp;

    int i,j;

    clrscr();

    printf("\nEnter a string : ");

    scanf("%s",str);

    printf("\n\nOriginal String     : %s",str);

    for(i=0;i<strlen(str);i=i+2){

    tmp = str[i];

    str[i] = str[i+1];

    str[i+1] = tmp;

    }

    printf("\nAfter Swap String      : %s",str);

    getch();

}

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.
...