Computer Science, asked by lavanyayannam419, 8 months ago

write a program for swaping of twon numbers in c​

Answers

Answered by Anonymous
0

#include<stdio.h>

double first, second, temp;

printf("Enter first number: ");

scanf("%lf", &first);

printf("Enter second number: ");

scanf("%lf", &second);

// Value of first is assigned to temp.

temp = first;

Answered by AskewTronics
0

C Program and the output for the above question is stated below:

Output :

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

If the user input as 5 and 6, then the output is 6 and 5.

Explanation:

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

void Swap(int first_number,int Second_number)//Swapping function which is used to swap the number.

{

   first_number=first_number+Second_number-(Second_number=first_number);//Swaping operation.

   printf("The first number is %d and the second number is %d after swapping",first_number,Second_number);//Print the number after swaping.

}

int main()//Main function.

{

   int first_number,Second_number;//Variable declaration.

   printf("Enter the two number for swapping: ");//Print the message for the input.

   scanf("%d %d",&first_number,&Second_number);//Take the input.

   Swap(first_number,Second_number);//Pass the input value to the function.

 return 0;

}

Code Explanation :

  • The above code is in C-language, in which the first line is used to instruct the user, then the second line is used to take the input and the third line is used to pass the value to the user-defined function for Swapping.
  • Then the swap function swap the number with the help of some operation, then the swapping value is printed on the screen.

Learn More ;

  • C-Program : https://brainly.in/question/3999878
Similar questions