Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.
Login
Login
OnlineGDB Q&A
Questions
Unanswered
Tags
Ask a Question
Ask a Question
write a program to swap two numbers without using variables
+6
votes
asked
Oct 10, 2019
by
Goldwyn Gedela
(
190
points)
c
language
Your answer
Your name to display (optional):
Email me at this address if my answer is selected or commented on:
Email me if my answer is selected or commented on
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
18 Answers
+2
votes
answered
Oct 11, 2019
by
rohan ag
(
1,310
points)
#include<stdio.h>
main()
{
int a=10,b=20;
a=a+b-(b=a);
printf("%d %d\n",a,b);
}
commented
Oct 13, 2019
by
KOTRAGOUDA
20 10 a value will be assign to b then the value of the b will be updated to 10,after that the a value will be calculated
Your comment on this answer:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
+2
votes
answered
Oct 11, 2019
by
Harsha
(
380
points)
without third variable we can swap but without any variables we cannt swap in c
Your comment on this answer:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
0
votes
answered
Oct 11, 2019
by
Eria Mutasa
(
140
points)
#include<stdio.h>
int main()
{
int first variable ;
int second variable;
printf("change the position of the first variable and second variable with each other");
return 0;
}
;
commented
Jun 13, 2020
by
xDELLx
(
10,500
points)
Bro you are awesome
Your comment on this answer:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
0
votes
answered
Oct 12, 2019
by
Rohan Ghobade
(
520
points)
https://onlinegdb.com/HJF-I7JFr
Your comment on this answer:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
0
votes
answered
Oct 12, 2019
by
anonymous
#include<stdio.h>
#include<conio.h>
int main()
{
int a=1;
int b=2;
a+b
a=(a+b)-a;
b=(a+b)-a;
Your comment on this answer:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
+1
vote
answered
Oct 12, 2019
by
saiteja
(
290
points)
#include <stdio.h>
int main()
{
int a,b,temp, *p, *q;
p=&a;
q=&b;
printf("Enter a and b:\n");
scanf("%d%d", &a,&b);
temp=*p;
*p=*q;
*q=temp;
printf("a=%d b=%d",*p,*q);
}
Your comment on this answer:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
0
votes
answered
Oct 13, 2019
by
Anand Sharma
(
150
points)
#include <stdio.h>
int main()
{
int a[2]={1,3};
printf("\n::No.s before swap::\n");
for(int i=0;i<2;i++)
{
printf("%d ",a[i]);
printf("and ");
}
printf("\n::No.s after swap::\n");
for(int i=1;i>=0;i--)
{
printf("%d ",a[i]);
printf("and ");
}
return 0;
}
Your comment on this answer:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
0
votes
answered
Oct 13, 2019
by
munna
(
140
points)
#include<stdio.h>
main()
{
int x,y;
x=10,y=20;
x=x^y;;
y=x^y;
x=x^y;
printf("%d %d",x,y);
}
commented
Oct 23, 2019
by
Subhadeep Deb Roy
check the 6th line and remove one semicolon ( ; ), else it is perfect
Your comment on this answer:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
0
votes
answered
Oct 13, 2019
by
prince
1
flag
#include<stdio.h>
void main()
{
int a,b;
printf("enter numbers a b:\n");
scanf("%d %d\n",&a,&b);
printf("%d %d\n",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("after swaping:\n");
printf("%d %d\n",a,b)
}
Your comment on this answer:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
0
votes
answered
Oct 13, 2019
by
Abhishek Kumar
#include<stdio.h>
int
{
int a, b;
printf ("enter numbers a,b:\n");
scanf ("%d %d\n", &a, &b);
printf ("%d %d\n", a, b);
a = a + b;
b = a - b;
a = a - b;
printf ("after swaping:\n");
printf ("%d %d\n", a, b)
}
Your comment on this answer:
Your name to display (optional):
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please
log in
or register.
Page:
1
2
next »
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...