a C prog to swap 2 no.s without using variables just an
array?

Answers were Sorted based on User's Feedback



a C prog to swap 2 no.s without using variables just an array?..

Answer / laxmi bose

#include<stdio.h>
main()
{
int a[0],a[1],a[2];
scanf("%d%d",&a[0],&a[1]);
a[2]=a[0];
a[0]=a[1];
a[1]=a[2];
printf("%d,%d",a[0],a[1]);
}

Is This Answer Correct ?    11 Yes 0 No

a C prog to swap 2 no.s without using variables just an array?..

Answer / sankar kiran

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("Enter the number:");
scanf("%d%d",&a,&b)
a=a+b;
b=a-b;
a=a-b;
printf("%d%d",a,b);
getch();

}

Is This Answer Correct ?    14 Yes 7 No

a C prog to swap 2 no.s without using variables just an array?..

Answer / jaspreet singh

void main()
{
int a[2]={20,10};
a[0]=a[0]^a[1];
a[1]=a[0]^a[1];
a[0]=a[0]^a[1];
printf("a=%d,b=%d",a[0],a[1])
getch();
}

Is This Answer Correct ?    7 Yes 4 No

a C prog to swap 2 no.s without using variables just an array?..

Answer / karthik

void main()
{
int a=10,b=20;
a^=b^=a^=b;
printf("a=%d,b=%d",a,b)
getch();
}

Is This Answer Correct ?    8 Yes 6 No

a C prog to swap 2 no.s without using variables just an array?..

Answer / baidyanath bisoyi

void main()
{
int a,b;
printf("enter the two numbers\n");
scanf("%d%d",&a,&b);
printf("a=%d\n b=%d\n",a,b);
a=a+b-(b=a);
printf("a=%d\n b=%d\n",a,b);
getch();
}

Is This Answer Correct ?    4 Yes 3 No

Post New Answer

More C Interview Questions

can anyone proide me reading material on svit00ef27@yahoo.com please thanx in advance

1 Answers   IBM,


Write a program to generate random numbers in c?

0 Answers  


What are header files in c programming?

0 Answers  


What are structural members?

0 Answers  


What is masking?

0 Answers  






Write a C program to find the smallest of three integers, without using any of the comparision operators.

7 Answers   TCS,


what is the use of operator ^ in C ? and how it works?

2 Answers  


write a program which counts a product of array elements lower than 10.

1 Answers  


What is a pointer?

1 Answers   ADP, IFFCO,


Program to write some contents into a file using file operations with proper error messages.

2 Answers  


Diff between for loop and while loop?

2 Answers   TCS,


can you change name of main()?how?

3 Answers   HCL, Siemens,


Categories