Question

Suppose you wanted to write a function to swap the value of two integers. int x...

Suppose you wanted to write a function to swap the value of two integers.

int x = 10;

int y = 20;

// call the swap function on x and y

// now x = 20, y = 10

Using C, write such a function.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

** Priclude <stdio.h> #include <conio.h> Pnt maincal ده =4 Pnt xay & Printf cee entes First number); Scanf ceedlod,&x); pr

Add a comment
Know the answer?
Add Answer to:
Suppose you wanted to write a function to swap the value of two integers. int x...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Design a swap function with the following interface: void swap( int *x,    int *y) { }...

    Design a swap function with the following interface: void swap( int *x,    int *y) { } In your main( ), you perform the following test: int main( ) {             int a = 10, b = 20;             cout << “a = “ << a << “   b= “   << b   << endl;             swap( a, b);             cout << “a = “ << a << “   b= “   << b   << endl;             return 0;                         … }

  • pick two answers 12 points). The function swap() should swap two integers and main() should print...

    pick two answers 12 points). The function swap() should swap two integers and main() should print those two swapped integers. What (if anything is wrong with this code? Select all that apply. oooo. No ure W..Ni def main(): X = 10 y = 2 x, y = swap(x,y). print(x,y) def swap(a,b): a = b temp = a b = temp main N on line 9, it is illegal syntax to introduce a new variable named temp. Instead, temp should be...

  • Write a C function that takes a long int y as argument as well as two...

    Write a C function that takes a long int y as argument as well as two integers n and m, the function should swap byte i and j of a long int y (64-Bit Integer).and returns a long int. long int swapBytes(long int y, int i, int j) Rules: Not allowed to use division, multiplication, or modulus, relative comparison (<, >, <=, >=), loops, switches, function calls, macros, conditionals (if or ?:) ALLOWED to use all bit level and logic...

  • Write a function shuffle that takes an array of 20 integers and then shuffles the integers...

    Write a function shuffle that takes an array of 20 integers and then shuffles the integers using the following algorithm. For each element X of the array, generate a random number N between 0 and 19, inclusive. swap X with the element that corresponds to N.

  • White a function that swaps values using templates int main ( ) { int X=5 int...

    White a function that swaps values using templates int main ( ) { int X=5 int Y=29 ; double a = 1.0 ; double b = 3.14 ; swap ( X , Y ) ; swap ( a , b ) ; return 0 ; } I need you to explain it step by step

  • Write a program whose input is two integers and whose output is the two integers swapped....

    Write a program whose input is two integers and whose output is the two integers swapped. Write in C language 7.3 LAB: Swapping variables Write a program whose input is two integers and whose output is the two integers swapped. Ex: If the input is: 38 then the output is: 83 Your program must define and call a function. SwapValues returns the two values in swapped order. void SwapValues(int* userVali, int* userVal2) ACRIVITY 7.3.1: LAB: Swapping variables 0/10 ] main.c...

  • Data structure c++ Write a recursive function, power, that takes two integers x and y as...

    Data structure c++ Write a recursive function, power, that takes two integers x and y as parameters such that x is nonzero and returns x'. You can use the following recursive definition to calculate xy: If y 20, y = 0; 1, power(x,y)= x, ( xx power(x, y-1), If y<0, y>1. power(x, y) = power(x,-y) Also, write a main function to test your function.

  • In C++, write a recursive function power that takes two positive integers base and n as...

    In C++, write a recursive function power that takes two positive integers base and n as inputs and computes base to the n power. Example power(3, 2) is 9. Do not use any loops in your program. This is what I got so far but I'm not sure what I'm doing wrong: #include <iostream> using namespace std; int calc(int x, int y); int main() {       calc(2, 3);    return 0; } int calc() {          cout...

  • Write a program that will accept two integers on command line, use the swap subprogram to...

    Write a program that will accept two integers on command line, use the swap subprogram to swap them, and then print the two numbers out. For example, I enter a.out 10 15 and the output that would print is 15 10. Please note that if exactly two numbers are not provided on command line, your program should display an error message and end with no further action. The programming language is C Compiler.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT