4 like 1 dislike

Write a program to swap the values of two variables. The program will ask the user to input variables x and y with numerical values. You must write code that exchanges their values: the value of x after your code runs must equal the value that y had before your code ran, and the value of y after your code runs must equal the value that x had before your code ran.

寫一個交換兩個變數的程式

Example input:

3
5

Example output:

5
3

Remember: Your output may be 100% correct, but your code matters!

[Exercise] Coding (C) - asked in Chapter 2: C Fundamentals by (11.3k points)
Available when: Unlimited - Due to: Unlimited

edited by | 566 views
0 0
u

61 Answers

0 like 0 dislike
Hidden content!
#include<stdio.h>

int main()
{
* * * * ** * ***** a,b,swap;
* * * ** ** * *** ** * * * * * * ** ** * ** *
* * ***** * ** ** * *
** ** ** * * * * * * * * *
**** * ***** ** *****
*** * ** ** ** *** ** * * ***
* * *** *** ** ***** **** *** 0;
}
answered by (82 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
int main()
{
** *** * * *** * first_number;
* * ** * * **** ** * ** ** second_number;
** ********* **** * * * swap;

***** * *** * * *** *** * * ** ***** ** ***** ** **** ** ** *


** ****** ** *** ** **** * **
*** * * * *** ** ** *** ** *** *
*** ** ***** ******* ** * * * *

* *** * *** ** ** **** * ** * **** ******* ***** *** );
** ** * * * * * ** ** * ** * ***** ******* **
*** ** * ** **** * 0;

}
answered by (-254 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
int main(){
** * ** * ** * a,b,temp;
* * *** * ** ** * ** ***** *** ***** * * ***** * *** **
** * ***** * * *** ** * * **
* *** ** ** * * ** * * **** *** * ** * * * ** * *
return 0;}
answered by (-32 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
int main()
{
int a,b;
** ** * ** ** ** ** ****** * *
* **** *** * ***** ***** * * *** ********* * ** ***
** * * * ********
**** ***** * * *
** *** *** ** **** ** ******
* **** ** * * * ** * ** ** * * *
return 0;
}
answered by (64 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
** * *** * *
* * (){
* ** * *
* * *** ** ** of x and y: *** ** *
*** *** * **** * *** * ***
** * * * * * ** ** of x= %d and the * of y * *** * *** *
****
* **
*** *
*** * * * x * y * * *** * * **


0;
}
answered by (16 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
* ** * * *** *
int ***
{
* *** *** a,b,swap;
* * ** * * * ** ** *
* * * * * **
swap=a;
a=b;
b=swap;
** * * * ****** * *** a);
******* ******* * **
* *** *** * * 0 ;
}
answered by (-254 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
** ***** **
main()
{
* * ** *** * * **
** * * ** * ** **** *
*** * ** * * *
swap=a;
a=b;
b=swap;
*** ******* * * * ** a);
* ** *** *** *
** * **** * * 0 ;
}
answered by (-254 points)
0 0
prog.c:2:1: warning: return type defaults to 'int' [-Wimplicit-int]
 main()
 ^~~~
0 like 0 dislike
Hidden content!
* * * * * ** *
 int main(){
int a,b;

**** ******* * * ** **** * ** *** *** ** ***** ****** *

** **** * * ** *** ****** *** ***** ****

return 0;
}
answered by (-32 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
** * * * *** * *
*** ** main(){
int a,b;

***** ** * *** *** * **** ** * *** *** * * * * * *

* * * *** * * * * * ***** * *** * *** ***

return 0;
}
answered by (-32 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int main(){
* * ******* ** * * *
** * * *** **** * * *** x,y,temp;
**** ** ** **** *** * *
*** ** * ** *** *** ** ** ** *** *** *
* * * *** *** * ** * * * * * ** * **
    
* **** * ******* * ** * = x;
**** ** * ** * *** *** * = y;
* * * ***** **** * = temp;
* ****** * * * * ** * **
* * * ** ****** ** ***** * ** * *** * ** x,y);
********* * *** ** **
* * ** * ** ***** ***** * ** 0;
}
answered
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Get it on Google Play Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.62.250
©2016-2020

Related questions

2 like 0 dislike
50 answers
[Exercise] Coding (C) - asked Sep 28, 2017 in Chapter 2: C Fundamentals by thopd (11.3k points)
Available when: Unlimited - Due to: Unlimited
| 424 views
1 like 0 dislike
73 answers
[Exercise] Coding (C) - asked Sep 28, 2017 in Chapter 2: C Fundamentals by admin (9.9k points)
Available when: Unlimited - Due to: Unlimited
| 522 views
3 like 0 dislike
116 answers
[Exercise] Coding (C) - asked Oct 5, 2017 in Chapter 3: Formatted Input/Output by thopd (11.3k points)
Available when: Unlimited - Due to: Unlimited
| 934 views
10,195 questions
107,716 answers
93,146 comments
3,262 users