Computer Science, asked by Tanmayrocket5362, 11 months ago

Write a 'C' program to swap the alternate digits of the given number

Answers

Answered by prativasahu2
0

#include <studio.h>

#include <conio.h>

void main(){

int a,b,c;

printf("enter the first number:");

scanf("%d" ,&a);

printf("enter the second number:");

scanf("%d" ,&b);

c = b;

b = a;

a = c;

printf("The first number is: %d \n The second number is: %d" ,a,b);

}

Answered by AskewTronics
0

Following are the program for the question above:

Explanation:

#include <stdio.h> //header file.

int main() //main function.

{

   int first_number,second_number; //variable declaration.

   printf("Enter first number and then second number"); //printf function.

   scanf("%d",&first_number); //take the input for the first number.

   scanf("%d",&second_number);//take the input for the second number.

   second_number=(first_number+second_number)-(first_number=second_number);//expression to replace the value.

  printf("The first number is: %d and the second number is: %d after replacement",first_number,second_number); //print the number after replacement.

   return 0;

}

Output:

  • If the user input as 12 and 4, then the output is 4 and 12.
  • If the user input as 4 and 12, then the output is 12 and 4.

Code Explanation:

  • The above code is in c++ language, in which firstly the user needs to enter the two value.
  • Then the value will be replaced and then print by the help of printf function.

Learn More:

  • C-program : https://brainly.in/question/637147
Similar questions