Single Choice
Easy
QWrite a function to swaps the values of two integers.
ID: #1367
Fundamentals of C Language
1,740 views
Question Info
#1367Q ID
EasyDifficulty
Fundamentals of C LanguageTopic
Your Answer
Choose the Best Option
Click any option to instantly check if you're correct.
Correct Answer
Explanation
Solution c Solution exist without any extra variables
1.
1.
void swap(int a, int b)
{
int c;
c=a;
a=b;
b=c;
}
2.
void swap (int a, int b)
{
a=a+b;
b=a-b;
a=a-b;
}
Solution2 is the best solution since no extra variable is required. Continue Practice
Share
Share This Question
Challenge a friend or share with your study group.
More from This Topic